Group of Stars
Group of Stars

Reputation: 36

Flutter localization Calendar

how are you? I have a problem to do localization flutter calendar to Mexico spanish. When I click the calendar button with locale('es') for calendar, I can see error on emulator that is "No MaterialLocalization found. DatePickerDialog widgets require MaterialLocalizations to be provided by a Localizations widget ancestor........".

class MyHomePage extends StatefulWidget {
  ...
class _MyHomePageState extends State<MyHomePage> {
  ...
  @override
  Widget build(BuildContext context) {
    ...
    return MaterialApp(
      ...
      home: ChildWidget()
    );   
 }


//ChildWidget
   class ChildWidget extends StatefulWidget {
      ...
      Widget build(BuildContext context) {
        ...
        return MaterialApp(
          //locale:const Locale('es','MX'),
          localizationsDelegates:[
            GlobalMaterialLocalizations.delegate,
            ...
          ],
          supportedLocales:[
            const Locale('en'),
            const Locale('es','MX')
          ],
          locale: const Locale('es','MX')
          home : ...
          ...

Upvotes: 0

Views: 105

Answers (1)

Group of Stars
Group of Stars

Reputation: 36

I did not set LocalizationDelegates property on super MaterialApp contained Wodget.

The component what I have set was not super MaterialApp contained Widget.

Widget build(BuildContext context) {
    return MaterialApp( 
       ...
       home: ChildWidget()
       ...
    )
}
//ChildWidget
class ChildWidget extends StatefulWidget {
...
 Widget build(BuildContext context) {
    ... //FutureBuilder will be here
    return MaterialApp( 
       localizationsDelegates: [
           AppLocalizationDelegate(),
           GlobalMaterialLocalizations.delegate,
       ],
       supportedLocales: [
         const Locale('en'),
         const Locale('es'),
       ],
       locale: snapshot.data,
       home: SingingPage()
       ...
    )
 }

This made that issue. So I moved all localization properties to super Widget.

Widget build(BuildContext context) {
    ... //FutureBuilder will be here
    return MaterialApp( 
       localizationsDelegates: [
           AppLocalizationDelegate(),
           GlobalMaterialLocalizations.delegate,
       ],
       supportedLocales: [
         const Locale('en'),
         const Locale('es'),
       ],
       locale: snapshot.data,
       home: ChildWidget()
       ...
    )
}
//ChildWidget
class ChildWidget extends StatefulWidget {

 Widget build(BuildContext context) {
    return MaterialApp( 
       ...
       home: SingingPage()
       ...
    )
 }

Upvotes: 0

Related Questions