【发布时间】:2020-08-21 21:36:54
【问题描述】:
我在按钮所在的位置有一个 statefull widged
onPressed: _exportData,
_exportData 以这种方式定义的地方
Future<void> _exportData() async {
...
setState(() {
_message = 'A message'; // I want to use localization string here
});
}
我需要将本地化字符串传递到上面的 setState() 中,我就是这样做的
Lang.key(ctx, 'about')
即我需要在那里传递上下文,但是当我尝试使它像这样时
onPressed: _exportData(ctx), // the error here
和
Future<void> _exportData(BuildContext ctx) async {...
onPressed出现错误
参数Future不能赋给参数类型 '无效函数()'
我如何在 _exportData 中传递上下文,或者如何在 _exportData 中使用本地化字符串?
更新:实际上没有必要将上下文传递到 _exportData,因为上下文在状态类中是可用的
【问题讨论】:
标签: flutter