Skip to content

Instantly share code, notes, and snippets.

@fonkamloic
Created November 14, 2019 03:53
Show Gist options
  • Save fonkamloic/617963260daed6019642c773e963dd93 to your computer and use it in GitHub Desktop.
Save fonkamloic/617963260daed6019642c773e963dd93 to your computer and use it in GitHub Desktop.
simple page route in flutter. Not refactored
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
theme: themeData,
home: Scaffold(
body: MyApp(),
),
),
);
}
final ThemeData themeData = ThemeData(
canvasColor: Colors.lightBlueAccent,
accentColor: Colors.redAccent,
);
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FlatButton(
child: Text("Go to page Two"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PageTwo(),
),
);
},
),
),
);
}
}
class PageTwo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: themeData.accentColor,
elevation: 1.0,
),
body: Center(
child: RaisedButton(
child: Text("Go to page Three"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PageThree(),
),
);
},
),
),
);
}
}
class PageThree extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: themeData.canvasColor,
elevation: 1.0,
title: Text("Last Page"),
),
body: Center(
child: FloatingActionButton(
child: Text("Go back to home"),
onPressed: () {
Navigator.popUntil(
context,
ModalRoute.withName(Navigator.defaultRouteName),
);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment