Skip to content

can't navigate! #6

Closed
Closed

Description

@hewa-jalal

i am getting this error when i navigate from my WelcomePage widget to another page

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Navigator operation requested with a context that does not include a Navigator.
E/flutter (28256): The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.

here is my main file

void main() {
  runApp(DevicePreview(builder: (context) => MyApp()));
}

class MyApp extends StatelessWidget {
  final GoogleSignIn _googleSignIn = GoogleSignIn();

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider<UserModel>(
          create: (_) => UserModel(),
        ),
        StreamProvider<FirebaseUser>.value(
            value: FirebaseAuth.instance.onAuthStateChanged),
      ],
      child: MaterialApp(
        builder: (context, widget) => ResponsiveWrapper.builder(
          WelcomePage(),
          maxWidth: 1200,
          minWidth: 450,
          defaultScale: true,
          breakpoints: [
            ResponsiveBreakpoint(breakpoint: 450, name: MOBILE),
            ResponsiveBreakpoint(
                breakpoint: 800, name: TABLET, autoScale: true),
            ResponsiveBreakpoint(
                breakpoint: 1000, name: TABLET, autoScale: true),
            ResponsiveBreakpoint(breakpoint: 1200, name: DESKTOP),
            ResponsiveBreakpoint(breakpoint: 2460, name: "4K", autoScale: true),
          ],
          background: Container(
            color: Color(0xFFF5F5F5),
          ),
        ),
        debugShowCheckedModeBanner: false,
      ),
    );
  }
}

my WelcomePage file

class WelcomePage extends StatefulWidget {
  @override
  _WelcomePageState createState() => _WelcomePageState();
}

class _WelcomePageState extends State<WelcomePage> {
  final _googleAuth = GoogleSignIn();

  @override
  void initState() {
    super.initState();
    googleSignInSilent();
  }

  void googleSignInSilent() {
    _googleAuth.signInSilently(suppressErrors: false).then((account) {
      if (account != null) {
        setState(() {
          // the error happens from here
          Navigator.pushReplacement(
            context,
            MaterialPageRoute(builder: (context) => FirstPage()),
          );
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 20),
          height: MediaQuery.of(context).size.height,
           Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'In Bed Ideas',
                style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
              ),
              SizedBox(
                height: 80,
              ),
              _submitButton(),
              SizedBox(
                height: 20,
              ),
              _signUpButton(),
              SizedBox(
                height: 20,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Activity

  1. rayliverified commented on Apr 22, 2020

    @rayliverified
    Contributor

    Please put the WelcomePage() in your MaterialApp's home parameter.

    MaterialApp's builder field is only for widgets and behaviors you want to apply to all MaterialApp children. The actual pages of your app need to go in home or a route.

  2. hewa-jalal commented on Apr 22, 2020

    @hewa-jalal
    Author

    i added it but nothing changed, in the documentation the builder method doesn't require a child but in my code it does, and that child get displayed instead of my MaterialApp home widget thus no context for descending widgets.

  3. hewa-jalal commented on Apr 22, 2020

    @hewa-jalal
    Author

    i fixed it by adding BouncingScrollWrapper.builder(context, widget) to builder method as a child, but i don't have a responsive UI!

  4. rayliverified commented on Apr 24, 2020

    @rayliverified
    Contributor

    The builder method expects a (context, widget) => widget value.
    You need to use MaterialApp's home parameter for all your widget construction. Please place your app's widgets in the home parameter.

    Set ResponsiveWrapper.builder as the Builder method. The code in the demo app might help https://github.com/Codelessly/FlutterMinimalWebsite

  5. hewa-jalal commented on Apr 24, 2020

    @hewa-jalal
    Author

    Okay got it, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions