Skip to content

Instantly share code, notes, and snippets.

@prasadsunny1
Last active May 17, 2020 09:40
Show Gist options
  • Save prasadsunny1/685057b6f49910f6e2473b71c602ff5a to your computer and use it in GitHub Desktop.
Save prasadsunny1/685057b6f49910f6e2473b71c602ff5a to your computer and use it in GitHub Desktop.
Navigate from one page to another
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Page1(),
),
);
}
class Page1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Page 1"),
),
body: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
child: Text("Go to page 2"),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return Page2();
},
),
);
// Navigator.of(context).pushReplacement(
// MaterialPageRoute(
// builder: (context) {
// return Page2();
// },
// ),
// );
},
),
],
),
),
),
);
}
}
class Page2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Page 2"),
),
body: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
child: Text("Go Back"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment