Repository navigation
Closed
Description
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,
),
],
),
),
),
);
}
}
Metadata
Metadata
Assignees
Labels
No labels
Activity
rayliverified commentedon Apr 22, 2020
Please put the
WelcomePage()in your MaterialApp'shomeparameter.MaterialApp's
builderfield is only for widgets and behaviors you want to apply to all MaterialApp children. The actual pages of your app need to go inhomeor a route.hewa-jalal commentedon Apr 22, 2020
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.
hewa-jalal commentedon Apr 22, 2020
i fixed it by adding
BouncingScrollWrapper.builder(context, widget)to builder method as a child, but i don't have a responsive UI!rayliverified commentedon Apr 24, 2020
The
buildermethod expects a(context, widget) => widgetvalue.You need to use
MaterialApp'shomeparameter for all your widget construction. Please place your app's widgets in thehomeparameter.Set
ResponsiveWrapper.builderas the Builder method. The code in the demo app might help https://github.com/Codelessly/FlutterMinimalWebsitehewa-jalal commentedon Apr 24, 2020
Okay got it, thank you.
Responsive Wrapper Test Creation #6