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,
),
),
),
),
),
我尝试从“ Question”类获取Text,并且将“ questionNum”用作索引。
我曾尝试Text(questionBamk[questionnum].questionText??'default value
显示“默认值”。
这是我一直在使用的班级代码
class Question {
String questionText ;
bool questionAnwsear;
Question ({String b ,bool a}){
b= questionText ;
a= questionAnwsear;
}
}
答案 0 :(得分:1)
尝试
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);