Flutter 在小部件定义中插入if-else语句
我在我的Flitter应用程序的类中插入了一个TableCalendar小部件Flutter 在小部件定义中插入if-else语句,flutter,Flutter,我在我的Flitter应用程序的类中插入了一个TableCalendar小部件 child: TableCalendar( calendarController: _calendarController, locale: 'es_ES', calendarStyle: CalendarStyle( todayColor: AppColors.naranjaCapenergy,
child: TableCalendar(
calendarController: _calendarController,
locale: 'es_ES',
calendarStyle: CalendarStyle(
todayColor: AppColors.naranjaCapenergy,
selectedColor: AppColors.azulCapenergy,
todayStyle: TextStyle(
fontWeight: FontWeight.bold,
)
),
),
我正在使用easy_本地化软件包使用该应用程序,让用户选择所需的UI语言
我包括了英语(en_en)和西班牙语(es_es)
我发现获取当前区域设置的方法如下:
print("current locale " + context.locale.toString());
在TableCalendar定义中,我想根据当前的区域设置更改参数locale:。
我试图插入if-else语句来更改locale参数,但编辑器中出现错误
根据当前区域设置的值,建议使用哪种方法更改TableCalendar定义中的区域设置参数?我只需插入当前区域设置值即可解决此问题,无需使用if else语句:
TableCalendar(
...
locale: context.locale.toString(),
...
)
请尝试
locale=(context.locale.toString()=“您想要的值”)?'en_en':'en_ES'
。您可以将区域设置设置为变量,并使用函数进行更改。@AmanVerma,这比我预期的要简单得多,请查看我自己的答案。谢谢。@Srilalsachitha,这比我想象的容易多了,请看一下我自己的答案。谢谢。您应该更改问题的标题,您的标题会询问如何插入if-else@AmanVerma,你说得对,这是我处理这个问题的第一个方法。@AmanVerma,我对你的评论投了赞成票,谢谢。