Max90
Max90

Reputation: 89

Flutter Navigation 2.0 + Bloc

I am currently trying to learn Navigation 2.0 in conjunction with BLoC.

I've followed the raywenderlich's guide [1] successfully (it's a bit outdated) and i tried to move forward managing the state with BLoC (this guide uses Provider) and when i did it successfully, i tried to take a step further and i tried to follow JalalOkbi's guide [2] because of a more advanced abstraction level provided. The third link [3] is the github repo with the full (now failing) project.

But after 5 days of trying i stumbled in several errors and i can't figure this out: i am currently facing this error:

I/flutter (10212): looking for /
I/flutter (10212): found Splash("null", null, null)
I/flutter (10212): looking for /
I/flutter (10212): found Splash("null", null, null)

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Builder:
The settings getter of a page-based Route must return a Page object. Please set the settings to the Page in the Page.createRoute method.
'package:flutter/src/widgets/navigator.dart':
package:flutter/…/widgets/navigator.dart:1
Failed assertion: line 3361 pos 9: 'entry.route.settings == page'


════════ Exception caught by widgets library ═══════════════════════════════════
A GlobalKey was used multiple times inside one widget's child list.
The relevant error-causing widget was
MaterialApp
lib\main.dart:40
════════════════════════════════════════════════════════════════════════════════

[1] https://www.raywenderlich.com/19457817-flutter-navigator-2-0-and-deep-links

[2] https://medium.com/@JalalOkbi/flutter-navigator-2-0-with-bloc-the-ultimate-guide-6672b115adf

[3] https://github.com/msimoncini90/flutter_navigation_2.0

Upvotes: 2

Views: 1544

Answers (1)

Steve Mitcham
Steve Mitcham

Reputation: 5313

If your page object is defined like

class SplashPage extends Page {

  @override
  Route createRoute(BuildContext context) {
    return MaterialPageRoute(
      builder: (BuildContext context) => const SplashScreen(),
    );
  }
}

The issue is that there is a missing setting in the page definition, which is what the error is showing. The correct code looks like

class SplashPage extends Page {
  @override
  Route createRoute(BuildContext context) {
    return MaterialPageRoute(
      settings: this,
      builder: (BuildContext context) => const SplashScreen(),
    );
  } 
}

Notice that the settings: this parameter, which solves what the error is describing.

Upvotes: 3

Related Questions