Skip to content

Instantly share code, notes, and snippets.

@rickyngan
Last active June 11, 2020 07:30
Show Gist options
  • Save rickyngan/5927c85551f0146fb8c0c5232494ba60 to your computer and use it in GitHub Desktop.
Save rickyngan/5927c85551f0146fb8c0c5232494ba60 to your computer and use it in GitHub Desktop.
2020 Jun 13 HoC HK Flutter: 7_route_navigator
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
child: Text('Open route'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
),
),
);
}
}
class SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment