Skip to content

Instantly share code, notes, and snippets.

@collinjackson
Created November 28, 2017 20:07
Show Gist options
  • Save collinjackson/77d55628d2e996053e9f17a16905c295 to your computer and use it in GitHub Desktop.
Save collinjackson/77d55628d2e996053e9f17a16905c295 to your computer and use it in GitHub Desktop.
Nested navigator example
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new Container(
color: Colors.white,
child: new MyAppHome(),
),
));
}
class Foo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
primary: true,
resizeToAvoidBottomPadding: false,
appBar: new AppBar(title: new Text('foo')),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.space_bar),
onPressed: () {
Navigator.of(context).push(new MaterialPageRoute(
builder: (_) => new Bar(),
));
},
),
);
}
}
class Bar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
primary: true,
resizeToAvoidBottomPadding: false,
appBar: new AppBar(title: new Text('bar')),
);
}
}
class MyAppHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
primary: false,
drawer: new Drawer(
child: new Center(
child: new Text('hello')
),
),
body: new Navigator(
onGenerateRoute: (RouteSettings settings) {
return new MaterialPageRoute(
builder: (_) => new Foo(),
);
},
),
);
}
}
@pishguy
Copy link

pishguy commented May 21, 2019

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