Category / Section
How to override the Material app locale and set English language for Flutter Calendar
2 mins read
In Flutter, can override the Material app locale with a different locale by using the Localization.override constructor.
This example demonstrates how to place SfCalendar and SfDateRangePicker in a Column widget while applying different localization settings to each. The SfCalendar is wrapped in a Localization.override constructor to override the inherited locale with English, while the SfDateRangePicker maintains the Material app's 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() ], ), )); } }