flutter - 文本是随机重复的
问题描述
我正在颤振中制作一个测验应用程序,但我遇到了问题。我希望我的问题不会重复。我正在使用 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]),
),
),
解决方案
推荐阅读
- java - 我们应该在 java 测试文件夹还是主文件夹中编写 testng selenium 代码?
- spring-boot - 使用 Facebook 登录:错误请求。主机和端口的这种组合需要 TLS
- django - 如何使用 kwargs 正确初始化类实例
- angularfire2 - 如何组合成角度的防火板?
- python - “Figure”对象没有“show”属性
- c - 当我在 c 中添加带有值的变量同时查找位数并打印数字的反转时获取垃圾值
- android - 有没有办法用 alarm_manager 启动颤动页面?
- amazon-web-services - 让 VPN 使用 NAT 网关
- r - 使用 ClusterEvalQ 编译 Rcpp 函数
- angular - 如何将动画添加到角度项目