我想在演出日期选择器中将语言从英语更改为法语,请在下面使用我正在使用的代码,以及应该解决的类似代码,但这会使该代码不适用于此部分:
new Step(
title: new Text("Quelle est la date de 1er immatriculation?"),
content: Column(
children: <Widget>[
Text(_datetime == null ? "Vous n'avez pas encore choisi de date" : _datetime.toString().substring(0, 10)),
RaisedButton(
child: Text('choisissez une date'),
onPressed: () {
showDatePicker(context: context,
locale : const Locale("fr","FR"),//this line making the code not working too
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.fallback(),
child: child,
);
},
// locale: const Locale('eu', 'FR'),
initialDate: DateTime.now(),
firstDate: DateTime(1920),
lastDate: DateTime(2100),
).then((date) {
setState(() {
_datetime = date;
});
});
}
),
],
),
isActive: _currentStep >= 0,
state:
_currentStep >= 2 ? StepState.complete : StepState.disabled,
),
flutter_localizations
插件,并在主代码的localizationDelegates
中指定supportedLocales
和MaterialApp
。以下是在French
中显示日期选择器的示例工作代码:flutter_localizations
中添加pubspec.yaml
插件并运行pub get
。MaterialApp
内部,添加以下内容:return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate
],
supportedLocales: [
const Locale('en'),
const Locale('fr')
],
....
body: Center( child: RaisedButton( child: Text('Tap'), onPressed: () { showDatePicker( context: context, locale : const Locale("fr","FR"), initialDate: DateTime.now(), firstDate: DateTime(2018), lastDate: DateTime(2030), builder: (BuildContext context, Widget child) { return Theme( data: ThemeData.dark(), child: child, ); } ); }, ) )
French
中看到日期选择器。希望这能回答您的问题。