断言失败:第 4263 行第 12 行:'_debugLifecycleState!= _ElementLifecycle.defunct':不是 true。扑

Sel*_*cer 6 debugging android exception flutter

我正在开发一个外语应用程序。我的申请中有多项选择题,但完成测试后出现此错误。我想知道是否有人知道这个错误的解决方案。

\n
    EXCEPTION : 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4263 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.\n    \n
Run Code Online (Sandbox Code Playgroud)\n

我的密码

\n
    class LoadJson extends StatelessWidget {\n      @override\n      Widget build(BuildContext context) {\n        return Scaffold(\n          body: FutureBuilder(\n            future: DefaultAssetBundle.of(context)\n                .loadString("lib/quiz/questions.json"),\n            builder: (context, snapshot) {\n              List mydata = json.decode(snapshot.data.toString());\n              if (mydata == null) {\n                return Center(\n                  child: Text("asld\xc3\xb6asid"),\n                );\n              } else {\n                return SorularinOlacagiPage(mydata: mydata);\n              }\n            },\n          ),\n        );\n      }\n    }\n    \n    class SorularinOlacagiPage extends StatefulWidget {\n      final mydata;\n    \n      const SorularinOlacagiPage({Key key, this.mydata}) : super(key: key);\n    \n      @override\n      _SorularinOlacagiPageState createState() =>\n          _SorularinOlacagiPageState(mydata: mydata);\n    }\n    \n    class _SorularinOlacagiPageState extends State<SorularinOlacagiPage>\n        with SingleTickerProviderStateMixin {\n      List<QuestionsModel> _myQuestions = new List<QuestionsModel>();\n      List mydata;\n    \n      _SorularinOlacagiPageState({this.mydata});\n    \n      Color colortoShow = Colors.indigo;\n      Color right = Colors.green;\n      Color wrong = Colors.red;\n      int index = 0;\n      int i = 1;\n      int marks = 0;\n      bool disableAnswer = false;\n      int j = 1;\n      int timer = 30;\n      String showTimer = "30";\n      var random_array;\n      Animation animation;\n      AnimationController animationController;\n      double beginAnim = 0.0;\n      double endAnim = 1.0;\n    \n      Map<String, Color> btnColor = {\n        "a": Colors.indigoAccent,\n        "b": Colors.indigoAccent,\n        "c": Colors.indigoAccent,\n        "d": Colors.indigoAccent\n      };\n      bool cancelTimer = false;\n    \n      genrandomarray() {\n        var distinctIds = [];\n        var rand = new Random();\n        for (int i = 0;;) {\n          distinctIds.add(rand.nextInt(20));\n          random_array = distinctIds.toSet().toList();\n          if (random_array.length < 20) {\n            continue;\n          } else {\n            break;\n          }\n        }\n        print(random_array);\n      }\n    \n//initstate\n      @override\n      void initState() {\n    //    startTimer();\n        genrandomarray();\n        super.initState();\n        _myQuestions = getQuestions();\n        animationController =\n            AnimationController(duration: const Duration(seconds: 8), vsync: this);\n        animation =\n            Tween(begin: beginAnim, end: endAnim).animate(animationController)\n              ..addListener(() {\n                setState(() {});\n              });\n        startAnim();\n        animationController.addStatusListener((status) {\n          if (status == AnimationStatus.completed) {\n            if (j < 20) {\n              j++;\n              resetAnim();\n              startAnim();\n            } else {\n              Navigator.of(context).pushReplacement(MaterialPageRoute(\n                  builder: (context) => TrueFalseSSonucSayfasi(marks: marks)));\n            }\n          }\n        });\n      }\n    \n    \n      startAnim() {\n        animationController.forward();\n      }\n    \n      resetAnim() {\n        animationController.reset();\n      }\n    \n      stopAnim() {\n        animationController.stop();\n      }\n    \n      @override\n      void setState(fn) {\n        if (mounted) {\n          super.setState(fn);\n        }\n      }\n    \n     /* void startTimer() async {\n        const oneSec = Duration(seconds: 1);\n        Timer.periodic(oneSec, (Timer t) {\n          setState(() {\n            if (timer < 1) {\n              t.cancel();\n              nextQuestion();\n            } else if (cancelTimer == true) {\n              t.cancel();\n            } else {\n              timer = timer - 1;\n            }\n            showTimer = timer.toString();\n          });\n        });\n      }*/\n    \n      void nextQuestion() {\n        if (j < 20) {\n          i = random_array[j];\n          j++;\n          resetAnim();\n          startAnim();\n        } else {\n          Navigator.pushReplacement(\n              context,\n              MaterialPageRoute(\n                  builder: (context) => TrueFalseSSonucSayfasi(\n                    marks: marks,\n                  )));\n        }\n        btnColor["a"] = Colors.indigoAccent;\n        btnColor["b"] = Colors.indigoAccent;\n        btnColor["c"] = Colors.indigoAccent;\n        btnColor["d"] = Colors.indigoAccent;\n        disableAnswer = false;\n      }\n    \n    \n    \n      void checkAnswer(String k) {\n        //Sorular -0 \xc5\x9f\xc4\xb1klar-1 cevaplar -1 =>index numarlar\xc4\xb1\n        if (mydata[2][i.toString()] == mydata[1][i.toString()][k]) {\n          //answer is correct\n          marks = marks + 5;\n          colortoShow = right;\n        } else {\n          //answer is wrong\n          colortoShow = wrong;\n        }\n        setState(() {\n          cancelTimer = true;\n          btnColor[k] = colortoShow;\n          disableAnswer = true;\n        });\n        Timer(Duration(seconds: 2), nextQuestion);\n      }\n    \n      Widget choiceButton(String k) {\n        return Padding(\n          padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),\n          child: MaterialButton(\n            onPressed: () => checkAnswer(k),\n            child: Text(\n              mydata[1][i.toString()][k],\n              style: TextStyle(color: Colors.white, fontSize: 16),\n              maxLines: 1,\n            ),\n            //color: btnColor[k],\n            color: btnColor[k],\n            splashColor: Colors.indigo.shade700,\n            highlightColor: Colors.indigo.shade700,\n            minWidth: 200,\n            height: 45,\n            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),\n          ),\n        );\n      }\n    \n      @override\n      Widget build(BuildContext context) {\n        SystemChrome.setPreferredOrientations(\n            [DeviceOrientation.portraitDown, DeviceOrientation.portraitUp]);\n        return WillPopScope(\n          child: Scaffold(\n            body: Column(\n              children: [\n                Container(\n                  padding: EdgeInsets.only(left: 30, right: 30, top: 20),\n                  child: Row(\n                    crossAxisAlignment: CrossAxisAlignment.end,\n                    children: [\n                      Text(\n                        "${j} / ${_myQuestions.length}",\n                        style: TextStyle(fontSize: 24, fontWeight: FontWeight.w500),\n                      ),\n                      Text(\n                        getTranslated(context, "ssoru"),\n                        style: TextStyle(fontSize: 17, fontWeight: FontWeight.w400),\n                      ),\n                      Spacer(),\n                      Row(\n                        crossAxisAlignment: CrossAxisAlignment.end,\n                        children: [\n                          Text(\n                            "$marks",\n                            style: TextStyle(\n                                fontSize: 24, fontWeight: FontWeight.w500),\n                          ),\n                          SizedBox(\n                            height: 10,\n                          ),\n                          Text(\n                            getTranslated(context, "puan"),\n                            style: TextStyle(\n                                fontSize: 17, fontWeight: FontWeight.w400),\n                          ),\n                        ],\n                      ),\n                    ],\n                  ),\n                ),\n                Expanded(\n                  flex: 1,\n                  child: Container(\n                    padding: EdgeInsets.all(15),\n                    alignment: Alignment.bottomLeft,\n                    child: Container(\n                      child: LinearProgressIndicator(\n                        value: animation.value,\n                      ),\n                    ),\n                  ),\n                ),\n                Expanded(\n                  flex: 3,\n                  child: Image.asset(\n                    mydata[0][i.toString()],\n                  ),\n                ),\n                Expanded(\n                  flex: 6,\n                  child: AbsorbPointer(\n                    absorbing: disableAnswer,\n                    child: Container(\n                      child: Column(\n                        mainAxisAlignment: MainAxisAlignment.center,\n                        children: [\n                          choiceButton("a"),\n                          choiceButton("b"),\n                          choiceButton("c"),\n                          choiceButton("d"),\n                        ],\n                      ),\n                    ),\n                  ),\n                ),\n              ],\n            ),\n          ),\n          onWillPop: () {\n            return showDialog(\n                context: context,\n                builder: (context) => AlertDialog(\n                      title: Text("Test"),\n                      content: Text("Bu A\xc5\x9famada Geri D\xc3\xb6nemezsin"),\n                      actions: [\n                        FlatButton(\n                          onPressed: () {\n                            Navigator.of(context).pop();\n                          },\n                          child: Text("Tamam"),\n                        ),\n                      ],\n                    ));\n          },\n        );\n      }\n    }\n
Run Code Online (Sandbox Code Playgroud)\n

例外

\n
\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception caught by animation library \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following assertion was thrown while notifying listeners for AnimationController:\n'package:flutter/src/widgets/framework.dart': Failed assertion: line 4263 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.\n\n  \n
Run Code Online (Sandbox Code Playgroud)\n

小智 0

void dispose()您必须在函数中像这样处理您的animationController 。

@override
void dispose() {
 _animationController.dispose();
 super.dispose();
Run Code Online (Sandbox Code Playgroud)

}

并确保super.dispose()事后致电