flutter - 在颤振中使用随机变量
问题描述
我只是想制作一个向用户提供随机文本的应用程序。但我很困惑,我无法访问我的变量。我不能将我的随机数附加到text
单词上。
这是我的变量:
var text1 = 'Of cource do it!';
var text2 = 'Do it.';
var text3 = 'why don\'t you do it faster?';
var text4 = 'I have no idea about it.';
var text5 = 'it\'s better to don\'t do it.';
var text6 = 'Don\'t do it.';
var text7 = 'if I was you , I would not do it.';
var text8 = 'Never do it.';
这是我制作随机数的方法:
void ran(){
numm = Random().nextInt(8)+1;
}
这就是我尝试用text
单词附加随机数的方式:
Text('$text$numm',style: TextStyle(color: Colors.white),)),
我怎样才能random number
混合text
?
解决方案
List<String> text = [
'Of cource do it!',
'Do it.',
'why don\'t you do it faster?',
'I have no idea about it.',
'it\'s better to don\'t do it.',
'Don\'t do it.',
'if I was you , I would not do it.',
'Never do it.'];
int ran() {
numm = Random().nextInt(8) + 1;
return numm;
}
然后像这样使用
Text(text[ran()],style: TextStyle(color: Colors.white),))
推荐阅读
- firebase - 我想知道如何在使用 firebase 运行应用程序时保持登录状态
- javascript - FullCalendar 在事件标题中显示 HTML
- php - 使用 dev_appserver.py 托管项目会为部署到 Google Cloud 提供不同的结果
- vagrant - 带有 Hyper-V 的 Vagrantbox 未启动
- css - 以 id 为目标的元素内的某处按 id 定位元素
- node.js - 如何在 cron 作业中设置 UTC 时区
- python - 从列表 Python 中删除后缀
- algorithmic-trading - 将 mql4 EA 转换为 mql5
- javascript - Json 到 csv 动态列 javascript
- python - 将 Google 表格转换为 PDF 并存储在与表格相同的 Google Drive 文件夹中