在调试控制台上在null上调用了该方法

时间:2019-12-11 17:15:06

标签: flutter consumer flutter-provider

当我运行我的应用程序时,如上图所示,我以静态方式仅获得我的主页,但是按任何按钮都没有移到下一个问题,如下面的代码所示,我在5个编辑器中创建了代码我只将主要

import './Quiz.dart';
import './Result.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
//@override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return MyAppState();
  }
}

class MyAppState extends State<MyApp> {
  var questionindex = 0;
  int totalscore;
  void resetquiz() {
    setState(() {
      questionindex = 0;
      totalscore = 0;
    });
  }

  void answerquestion(int score) {
    totalscore += score;
    setState(() {
      questionindex = questionindex + 1;
      print(questionindex);
    });
  }

  Widget build(BuildContext context) {
    var questions = [
      {
        'question text': 'what is your title ?',
        'answer text': [
          {'text': 'manager (high) ', 'score': 10},
          {'text': 'engineer (meduim) ', 'score': 5},
          {'text': 'technician (low)', 'score': 0},
        ]
      },
      {
        'question text': 'who is your ex boss ?',
        'answer text': [
          {'text': 'kan mot5lf (high)', 'score': 10},
          {'text': 'mabyfhmsh (meduim)', 'score': 5},
          {'text': '7omar molla (low)', 'score': 0}
        ]
      }
    ];
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.deepPurple[400],
        appBar: AppBar(
          centerTitle: true,
          backgroundColor: Colors.grey[800],
          title: Text(
            'Definition App',
            style: TextStyle(fontSize: 36),
          ),
        ),
        body: questionindex < questions.length
            ? Quiz(
                answerquestion: answerquestion,
                questions: questions,
                questionindex:
                    questionindex) 

            : Result(totalscore, resetquiz),
      ),
    );
  }
}

按下任何按钮时,我都会在调试控制台中找到错误消息

════════手势捕获异常═══════════════════════════════════ ════════ 处理手势时引发了以下NoSuchMethodError: 方法“ +”在null上被调用。 接收者:null 尝试致电:+(10)

图像:

enter image description here

0 个答案:

没有答案