Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GlobalMaterialLocalizations.delegate provides error

Tags:

flutter

EDIT: Answer was very simple:

await initializeDateFormatting('pl_PL');

Above code was in conflict with:

GlobalMaterialLocalizations.delegate

Removing initializeDateFormatting helps.


I made a localization on my Flutter app. Unfortunately when I add GlobalMaterialLocalizations.delegate to localizationsDelegates there is an error. Removing GlobalMaterialLocalizations.delegate provides app to work correctly but only English version. Another language (Polish) has a problem with AppBars (Again - after removing it (appbar) app works fine in that language too).

Part of my code:

localizationsDelegates: [
  const ReadyLocalizationsDelegate(),
  GlobalMaterialLocalizations.delegate,
  GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
  const Locale('en', 'US'),
  const Locale('pl', 'PL'),
],

Error:

Unsupported operation: Cannot set value in unmodifiable Map

Here is an error when I comment GlobalMaterialLocalizations.delegate (page has AppBar): https://pastebin.com/ENF5ZET7

As I said there is no error when localization is set to English.

like image 855
edi_smooth Avatar asked Jan 31 '19 11:01

edi_smooth


2 Answers

If you just want to use the system's locale setting, there is no need to call initializeDateFormatting(). In your main.dart before calling runApp(), do this:

await findSystemLocale();

To call this method, you will need this import:

import 'package:intl/intl_standalone.dart';

As a reference, there is some documentation here -- https://api.flutter.dev/flutter/intl/Intl/systemLocale.html

like image 25
Ryan Jones Avatar answered Nov 02 '22 16:11

Ryan Jones


await initializeDateFormatting('pl_PL');

Above code was in conflict with:

GlobalMaterialLocalizations.delegate

Removing initializeDateFormatting helps.

like image 132
edi_smooth Avatar answered Nov 02 '22 16:11

edi_smooth