Category / Section
How to override the Material app locale and set English language for Flutter Calendar
2 mins read
In Flutter, override the Material app locale with different locale by using the Localization.override constructor.
The SfCalendar and SfDateRangePicker control is present in the Column widget. Place the SfCalendar in the Localization.override constructor in which the inherited locale (defined in Material app locale) or LocalizationsDelegate for child has been overridden with English language for SfCalendar and SfDateRangePicker has Material app locale.
import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:syncfusion_flutter_calendar/calendar.dart'; import 'package:syncfusion_flutter_datepicker/datepicker.dart'; void main() => runApp(LocalizationSupport()); class LocalizationSupport extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( localizationsDelegates: [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], supportedLocales: [ const Locale('en'), const Locale('zh'), const Locale('he'), const Locale('ru'), const Locale('fr', 'BE'), const Locale('fr', 'CA'), const Locale('ja'), const Locale('de'), const Locale('hi'), const Locale('ar'), ], locale: const Locale('zh'), debugShowCheckedModeBanner: false, home: CustomStringLocale(), ); } } class CustomStringLocale extends StatefulWidget { @override State<StatefulWidget> createState() => ScheduleExample(); } class ScheduleExample extends State<CustomStringLocale> { @override Widget build(BuildContext context) { return (Scaffold( body: Column( children: [ Localizations.override( context: context, locale: Locale('en'), child: Expanded(child: SfCalendar()), ), SfDateRangePicker() ], ), )); } }