Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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(),
);
},
),
);
}
}
@MahdiPishguy

This comment has been minimized.

Copy link

commented May 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.