Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 断言失败:第4263行位置12:'_debugLifecycleState!=_ElementLifecycle.defunct';:事实并非如此。颤振_Android_Flutter_Debugging_Exception - Fatal编程技术网

Android 断言失败:第4263行位置12:'_debugLifecycleState!=_ElementLifecycle.defunct';:事实并非如此。颤振

Android 断言失败:第4263行位置12:'_debugLifecycleState!=_ElementLifecycle.defunct';:事实并非如此。颤振,android,flutter,debugging,exception,Android,Flutter,Debugging,Exception,我正在开发一个外语应用程序。我的应用程序中有多项选择题,但在我完成测试后,出现了此错误。我想知道是否有人知道这个错误的解决办法 EXCEPTION : 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4263 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true. 我的代码 class L

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

    EXCEPTION : 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4263 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
    
我的代码

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