How to change language of Show date picker in flutter
In order to show the date picker in local language, you need to make use of flutter_localizations
plugin and specify localizationDelegates
and supportedLocales
inside MaterialApp
in your main code. Below is sample working code that shows datepicker in French
:
- Add
flutter_localizations
plugin inpubspec.yaml
and runpub get
.
- Import the plugin in dart file.
Inside
MaterialApp
, add following: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, ); } ); }, ) )
Run app again (hot restart) and see that datepicker shows up in
French
.
Hope this answers your question.
I followed @Darshan's answer but I got the following error :
Unsupported operation: Cannot set value in unmodifiable Map
after I removed await initializeDateFormatting('fr_FR');
from main.dart
it worked well for me , enjoy