Home > Net >  iam having exception this Exception has occurred. _CastError (type 'Null' is not a subtype
iam having exception this Exception has occurred. _CastError (type 'Null' is not a subtype

Time:06-15

I'm having null exception:

 body: Center(
                child: Column(
              children: [
                Row(
                  children: const [
                    Icon(
                      Icons.check_circle,
                      color: Colors.green,
                    ),
                    Icon(
                      Icons.clear,
                      color: Colors.red,
                    ),
                  ],
                ),
                Container(
                  width: double.infinity,
                  height: 130.0,
                  margin:
                      EdgeInsets.only(bottom: 10.0, left: 30.0, right: 30.0),
                  padding:
                      EdgeInsets.symmetric(horizontal: 50.0, vertical: 20.0),
                  decoration: BoxDecoration(
                      color: Colors.deepOrange,
                      borderRadius: BorderRadius.circular(10.0)),
                  child:  Center(
                      child: Text(
                        _questions[_questionIndex]['questions'] as String,
                          textAlign: TextAlign.center,
                          style: TextStyle(
                            fontSize: 20.0,
                            color: Colors.white,
                            fontWeight: FontWeight.bold,
                          ))),
                ),
                ...(_questions[_questionIndex]['answers'] as List<Map<String, Object>>).map((answer) {                  
                  
                  return Answer(answerrText: answer['answerText'] as String )  ;
                }
               ),

CodePudding user response:

Can you try this?

if(answer['answerText'] != null)
return Answer(answerrText: answer['answerText'] as String);

CodePudding user response:

There is no need of type allocation just try this,

return Answer(answerrText: "${answer['answerText'].toString()}" ) ;

  • Related