flutter - 如何在 Flutter 中更新 Text()
问题描述
如何使用 RaisedButton 更新 Text()?
我需要在没有 setState 的情况下运行它
RaisedButton(
child: Text('Press Me To update Text !'),
onPressed: (){
changetext = 'it has been changed';
},
)
谢谢你帮助我:)
解决方案
首先,你必须在 aStatefulWidget
中,这样你才能调用setState
。如果您在不调用的情况下更改变量,setState
您将不会在 UI 中看到更改。
您必须将文本存储在变量中
String _text = 'Press Me To update Text !';
并像这样更新它;
RaisedButton(
onPressed: () {
setState(() {
_text = 'The text is updated';
});
},
child: Text(_text),
)
这是整个应用程序,您可以自己运行它。
推荐阅读
- php - 这些额外的查询结果从何而来?
- php - 如何从 WC_Order_Item_Shipping 获取产品
- excel - 在 Matlab 中无法使用 xlsread 打开 Excel 文件
- angular - 如何根据解析的路由数据路由到子路由?
- django - 在django中选择进程数时重复客户端和进程创建
- python - 将一些表格内容写入文本文件时遇到问题
- python - 如何限制数据框中的 cumsum 并减去所有值
- c# - 如何从C#中的数组中获取所有非空值
- ios - 如何正确禁用/启用推送通知
- spring-jms - 我们应该使用 JmsOperations 而不是 JmsTemplate 吗?(同样 JmsMessagingOperations vs JmsMessagingTemplate)