Localization in Flutter Date Range Picker (SfDateRangePicker)

23 Apr 20211 minute to read

By default, the calendar widget supports US English localizations. You can change other languages by specifying the MaterialApp properties and adding the flutter_localizations package to your application.

As of February 2020, flutter package supports 77 languages.

To use flutter_localizations, add the package as a dependency to pubspec.yaml file.

  • dart
  • dependencies:
    flutter_localizations:
      sdk: flutter

    Next, import the flutter_localizations library and specify localizationsDelegates and supportedLocale for MaterialApp.

    import 'package:flutter_localizations/flutter_localizations.dart';
    
    @override
    Widget build(BuildContext context) {
    return MaterialApp(
            localizationsDelegates: [
                GlobalMaterialLocalizations.delegate,
                GlobalWidgetsLocalizations.delegate,
          ],
         supportedLocales: [
              const Locale('zh'),
              const Locale('ar'),
              const Locale('ja'),
          ],
          locale: const Locale('zh'),
          title: 'DateRangePicker Localization',
          home: Scaffold(
              appBar: AppBar(
              title: Text('Calendar'),
              ),
              body: SfDateRangePicker(
              view: DateRangePickerView.month,
               ),
           ),
       );
    }

    Localization Date Range Picker