het*_*dhi 4 dart android-studio flutter
我想了解如何在我的颤振代码中应用“if”条件?因为我是 dart 语言编码的新手。
假设在如下代码中,我想添加条件,如果计数器的值为 1,则“您已按下按钮 $_counter 次”,否则“您已按下按钮 $_counter 次”
children: <Widget>[
new Text(
'You have pushed the button $_counter times:',
)/*,
new Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),*/
]
Run Code Online (Sandbox Code Playgroud)
PS这只是一个简单的例子,让我了解如何在颤振中使用 if 条件。
对于这种简单的情况,您可以使用三元 if?:内部字符串插值:
new Text(
'You have pushed the button $_counter time${_counter != 1 ? 's' : ''}:',
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10370 次 |
| 最近记录: |