Created
April 20, 2022 20:17
-
-
Save nemrosim/c5c61a6bf5e431ecc31451ca0fcf80fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
initialRoute: '/', | |
routes: { | |
// When navigating to the "/" route, build the FirstScreen widget. | |
'/': (context) => const HomePage(), | |
// When navigating to the "/second" route, build the SecondScreen widget. | |
'/second': (context) => const Page2(), | |
}, | |
); | |
} | |
} | |
class HomePage extends StatelessWidget { | |
const HomePage({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Home page'), | |
), | |
body: Center( | |
child: Column( | |
children: <Widget>[ | |
ElevatedButton( | |
child: const Text('Simple transition'), | |
onPressed: () { | |
Navigator.of(context).pushNamed('/second'); | |
}, | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class Page2 extends StatelessWidget { | |
const Page2({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Page 2'), | |
), | |
body: const Center( | |
child: Text( | |
'Page 2', | |
style: TextStyle(fontSize: 30), | |
))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment