Reputation: 36
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
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