Skip to content

Instantly share code, notes, and snippets.

@vemarav
Last active October 25, 2018 07:45
Show Gist options
  • Save vemarav/4b194c55792c91a50716b28d07ac7113 to your computer and use it in GitHub Desktop.
Save vemarav/4b194c55792c91a50716b28d07ac7113 to your computer and use it in GitHub Desktop.
Flutter Navigation Routing
import 'package:flutter/material.dart';
const String _AccountName = 'Aravind Vemula';
const String _AccountEmail = '[email protected]';
const String _AccountAbbr = 'AV';
void main() => runApp(new Keeper());
class Keeper extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Keeper',
theme: new ThemeData(
primaryColor: Colors.yellow.shade700
),
home: new KeeperDrawer(),
// Routes
routes: <String, WidgetBuilder> {
Notes.routeName : (BuildContext context) => new Notes()
}
);
}
}
class KeeperDrawer extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
drawer: new Drawer(
child: new ListView(
padding: const EdgeInsets.only(top: 0.0),
children: <Widget>[
new UserAccountsDrawerHeader(...),
new ListTile(
leading: new Icon(Icons.lightbulb_outline),
title: new Text('Notes'),
onTap: () {
Navigator.of(context).pop();
// Navigator.of(context).pushNamed(Notes.routeName) won't have
// transition animation and can be used for modal forms
// Which we will see in Forms & Validation.
// Navigator.of(context).pushNamed(Notes.routeName);
// To add transition we are using PageRouteBuilder
Navigator.of(context).push(
new PageRouteBuilder(
pageBuilder: (BuildContext context, _, __) {
return new Notes();
},
transitionsBuilder: (_, Animation<double> animation, __, Widget child) {
return new FadeTransition(
opacity: animation,
child: child
);
}
)
);
},
),
// ... collapsed
...
]
)
),
appBar: new AppBar(
title: new Text('Keeper'),
),
body: new Center(
child: new Text('Hello World!')
)
);
}
_onTapOtherAccounts(BuildContext context) {...}
_onListTileTap(BuildContext context) {...}
}
class Notes extends StatelessWidget {
static final String routeName = '/notes';
@override
Widget build(BuildContext context) {
return new Scaffold(
drawer: new Drawer(),
appBar: new AppBar(
title: new Text('Notes'),
),
body: new Center(
child: new Text(
'Notes',
style: new TextStyle(
fontSize: 24.0
)
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment