Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Add the following code
Localizations.override(
context: context,
locale: const Locale('es'),
// Using a Builder to get the correct BuildContext.
// Alternatively, you can create a new widget and Localizations.override
// will pass the updated BuildContext to the new widget.
child: Builder(
builder: (context) {
// A toy example for an internationalized Material widget.
return CalendarDatePicker(
initialDate: DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime(2100),
onDateChanged: (value) {},
);
},
),
),
],
),
),
);
}
2条答案
按热度按时间j0pj023g1#
您可以创建一个新的AppLocalizations示例,其中包含您想要的句子。
因此,您可以使用.of(context)来获取Locale,而是将所需的Locale提供给AppLocalizations
希望能帮上忙。
relj7zay2#
已由本地化解决。override和Builder。更多信息https://docs.flutter.dev/development/accessibility-and-localization/internationalization in“Overriding Locale”