首页 > 解决方案 > 文本是随机重复的

问题描述

我正在颤振中制作一个测验应用程序,但我遇到了问题。我希望我的问题不会重复。我正在使用 Shake 包来更改问题(用户摇动手机以查看新问题)但在这里变得更加棘手。我有 21 个问题,但我只看到 10 个,因为代码重复了一个问题两次。我应该为应用程序更改什么以抛出所有问题而不是重复它们?

int index = 0;
  String _question = question.first;
  ShakeDetector detector;
  Vibration vibration;
  var countdown;

  @override
  void initState() {
    super.initState();
     detector = ShakeDetector.autoStart(onPhoneShake: () {
      final newQuestion = (List.of(question)..remove(_question)..shuffle()).first;
      setState(() {
        this._question = newQuestion;
        Vibration.vibrate(duration: 1000);
        controller.reset();
      });
    }
    );

...

Align(
                                  alignment: FractionalOffset.center,
                                  child: Column(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceEvenly,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: <Widget>[
                                      
                                      SizedBox(height: 10),
                                      Container(
                                        height: 70,
                                        width: 230,
                                        child: Text(
                                          _question,
                                          textAlign: TextAlign.center,
                                          style: TextStyle(
                                              fontSize: 16.0,
                                            
                                              fontWeight: FontWeight.bold,
                                              color: Colors.indigoAccent[700]),
                                        ),
                                      ),

标签: flutter

解决方案


推荐阅读