Reputation: 1533
I need to use CupertinoDatePicker
, however its date formatting is mm-dd-yyyy
, which in fact is not common for a specific location, where my app will be distributed. I would like to change the format to dd-mm-yyyy
, which IMO seems more general.
Is that possible, using that picker?
Upvotes: 1
Views: 2184
Reputation: 206
EDIT: It should be possible in Flutter version 1.7
According to the CupertinoDatePicker documentation:
the class will display its children as consecutive columns. Its children order is based on internationalization.
You can read more about internationalization Flutter apps here.
You need to add this to your pubspec.yaml
file:
dependencies:
flutter_localizations:
sdk: flutter
And then in your root widget add proper localizationsDelegates:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Application',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''),
const Locale('fr', ''),
],
home: Scaffold(
body: Container(),
),
);
}
}
If you'll use in app one of the localizations that supports dd-mm-yyyy
format, e.g. UK English, and you'll have this language set on your device, you should see this widget changed accordingly.
Upvotes: 1