singerdmx / flutter-quill

Rich text editor for Flutter
https://pub.dev/packages/flutter_quill
MIT License
2.58k stars 829 forks source link

type 'Null' is not a subtype of type 'WidgetsLocalizations' in type cast #2098

Closed Xoshbin closed 2 months ago

Xoshbin commented 2 months ago

Is there an existing issue for this?

Flutter Quill version

10.1.9

Steps to reproduce

Setup Quill with a language that is not supported in Flutter but in Quill like Kurdish, and run the app

Expected results

Show the Quill editor

Actual results

When i run my App that have a screen with Quill editor with a language like English it's showing the editor but for Kurdish language whereas the locale file available in Quill but it's giving the error above.

and this is the merge commit that I added the missing Kurdish phrases https://github.com/singerdmx/flutter-quill/pull/2029

AtlasAutocode commented 2 months ago

Firstly, I am NOT an expert on localizations.

I note that you understand that Kurdish is not supported by Flutter. There is a lot of early startup code that checks to make sure that flutter apps have access to Localizations. I assume this is because flutter's internal operations have many dependencies, and flutter might not work correctly without this localization support.

On my windows desktop, the code seems to expect MaterialLocalizations will be present. Theme.of expects an instance of this class and is called frequently.

Localization support is provided in the startup code for your app:

            localizationsDelegates: const [
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
              // Uncomment this line to use provide flutter quill localizations
              // in your widgets app, otherwise the quill widgets will provide it
              // internally:
              // FlutterQuillLocalizations.delegate,
            ],

Uncommenting the last line does not provide the missing localization type. I expect you are going to have to provide your own localizations delegate to bypass flutter's default behavior and provide the missing localization of type appropriate to your environment.

Can you contact the Flutter localization team to ask them to support Kurdish? This would make it easy to fix this problem.

Xoshbin commented 2 months ago

@AtlasAutocode Thank you for helping, even though I have tried multiple times before without working, but this time after making sure I'm doing the right thing and after a flutter clean it did work.

localizationsDelegates: const [
                    AppLocalizations.delegate,
                    GlobalMaterialLocalizations.delegate,
                    GlobalWidgetsLocalizations.delegate,
                    GlobalCupertinoLocalizations.delegate,
                    KuMaterialLocalizations.delegate,
                    KuCupertinoLocalizations.delegate,
                    KuWidgetLocalizations.delegate,
                    FlutterQuillLocalizations.delegate,
                  ],