A non-null String must be proided to a text widget

Adil Sakout :
List<Question> questionBank =[
    Question(b: 'You can lead a cow down stairs but not up stairs.', a: true) ,
    Question(b: 'Approximately one quarter of human bones are in the feet.',a: false),
    Question(b: 'A slug\'s blood is green.',a: false),
  ];
  int questionNum=0;
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: <Widget>[
        Expanded(
          flex: 5,
          child: Padding(
            padding: EdgeInsets.all(15.0),
            child: Center(
              child: Text(
               questionBank[questionNum].questionText,
                style: TextStyle(
                  fontSize: 30.0,
                  fontWeight: FontWeight.bold,
                  color: Colors.white,
                ),
              ),
            ),
          ),
        ),

I try to get Text from class 'Question' and, I use 'questionNum' like an index. I had try to Text(questionBamk[questionnum].questionText??'default value it show 'default value'. this is the class code I have been use it

class Question {
  String questionText ;
  bool questionAnwsear;
  Question ({String b ,bool a}){
    b= questionText ;
    a= questionAnwsear;
  }
}
Henok :

Try

questionBank[questionNum].questionText!=null?questionBank[questionNum].questionText : 'loading ...'


//change your class like this,
class Question {
  String questionText ;
  bool questionAnwsear;
  Question({this.questionText ,this.questionAnwsear});
}

//then call like 

Question(questionText: 'You can lead a cow down stairs but not up stairs.', questionAnwsear : true);


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=382858&siteId=1