Easy_localization: Can't get new state in BlocListener due to easy_localization

Created on 18 Apr 2020  路  8Comments  路  Source: aissat/easy_localization

Hello.
I have an application with bloc and easy_localization. My app loads SplashPage until everything is ready, and after that it changes the page. All fine and obvious without localizations, but when it is turned on, a new state will not be received and the SplashPage will not change to the FirstPage.
Please check minimal working example here.
How can I fix it?

All 8 comments

@don-prog plz log msg and why create app_localizations.dart :(

@aissat thanks for your reply!

  1. app_localizations.dart - was a legacy from a previous localization try and did absolutely nothing in this repo. I got rid of it in the last commit, you can check.
  2. easy_localization logs:

[log] EasyLocalization
[log] initState
[log] easy localization: Build
[log] easy localization: Device locale en_US
[log] easy localization: Load asset from resources/langs
[log] easy localization: Build
[log] easy localization: Init Localization Delegate
[log] easy localization: Init provider
[log] easy localization: Load Localization Delegate

@don-prog easy_localization working well, about app_localizations.dart u do not need it

@aissat yes, I understand that, so, as I said, I deleted it :)
But of course it didn鈥檛 change anything and there is still a problem.

@don-prog I'll check ur code

@don-prog @aissat try like this #125

@Overman775 thanks for suggestion, but I use the bloc in many places, I can't just use Provider in one place as Ad hoc due to the consistency. Maybe you can provide a solution for the bloc?

@don-prog problem in your code, you send event to bloc but listener not created at this moment, use BlockBuilder

  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        EasyLocalization.of(context).delegate,
      ],
      supportedLocales: EasyLocalization.of(context).supportedLocales,
      locale: EasyLocalization.of(context).locale,
      home: Scaffold(
        body: BlocBuilder<MainBloc, MainState>(
          builder: (context, state) {
            print(state);
            if (state is ReadyState) {
              print('first_page');
              return Navigator(
                key: rootNavigatorKey,
                initialRoute: 'first_page',
                onGenerateRoute: RouteGenerator.generateRoute,
              );
              //return FirstPage();
            } else {
              print('splash_page');
              return SplashPage();
              /*
              ///your variant
              return Navigator(
                key: rootNavigatorKey,
                initialRoute: 'splash_page',
                onGenerateRoute: RouteGenerator.generateRoute,
              );*/
            }
          },
        ),
      ),
    );
  }
Was this page helpful?
0 / 5 - 0 ratings