Flutter 必须向文本小部件提供非空字符串

Flutter 必须向文本小部件提供非空字符串,flutter,Flutter,试一试 @GenchiGenbutsu你能帮我吗?@AdilSakout查看我的更新答案现在没有错误,但显示“正在加载…”,我需要从类中获取字符串你知道什么是?运算符吗?@GenchiGenbutsu是的,我非常熟悉空值运算符,你应该知道不使用并不总是不知道的,但是谢谢你的提问。如果你写了questionBank[questionNum].questionText这样的东西,显然不太好=空?questionBank[questionNum]。questionText:“正在加载…”而只是ques

试一试


@GenchiGenbutsu你能帮我吗?@AdilSakout查看我的更新答案现在没有错误,但显示“正在加载…”,我需要从类中获取字符串你知道什么是
运算符吗?@GenchiGenbutsu是的,我非常熟悉空值运算符,你应该知道不使用并不总是不知道的,但是谢谢你的提问。如果你写了
questionBank[questionNum].questionText这样的东西,显然不太好=空?questionBank[questionNum]。questionText:“正在加载…”
而只是
questionBank[questionNum]。questionText??'正在加载…“
?”??仅当变量为null,但类不为空时才赋值
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,
                ),
              ),
            ),
          ),
        ),
class Question {
  String questionText ;
  bool questionAnwsear;
  Question ({String b ,bool a}){
    b= questionText ;
    a= questionAnwsear;
  }
}
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);