Created
September 6, 2021 07:38
-
-
Save stansidel/ba913bcc009066c1feb503345f0850f1 to your computer and use it in GitHub Desktop.
Flutter Cupertino Basic Navigation
This file contains hidden or 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/cupertino.dart'; | |
void main() { | |
runApp(CupertinoApp( | |
home: MyAppHome(), // becomes the route named '/' | |
routes: <String, WidgetBuilder>{ | |
'/a': (BuildContext context) => const MyPage(title: 'page A'), | |
'/b': (BuildContext context) => const MyPage(title: 'page B'), | |
'/c': (BuildContext context) => const MyPage(title: 'page C'), | |
}, | |
)); | |
} | |
class MyAppHome extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return CupertinoPageScaffold( | |
// Uncomment to change the background color | |
// backgroundColor: CupertinoColors.systemPink, | |
navigationBar: const CupertinoNavigationBar( | |
middle: Text('Sample Code'), | |
), | |
child: ListView( | |
children: <Widget>[ | |
CupertinoButton( | |
child: const Text('Go to A'), | |
onPressed: () => Navigator.of(context).pushNamed('/a'), | |
), | |
CupertinoButton( | |
child: const Text('Go to B'), | |
onPressed: () => Navigator.of(context).pushNamed('/b'), | |
), | |
CupertinoButton( | |
child: const Text('Go to C'), | |
onPressed: () => Navigator.of(context).pushNamed('/c'), | |
), | |
], | |
), | |
); | |
} | |
} | |
class MyPage extends StatelessWidget { | |
final String title; | |
const MyPage({required this.title}); | |
@override | |
Widget build(BuildContext context) { | |
return CupertinoPageScaffold( | |
// Uncomment to change the background color | |
// backgroundColor: CupertinoColors.systemPink, | |
navigationBar: CupertinoNavigationBar( | |
automaticallyImplyLeading: true, | |
middle: Text(title), | |
), | |
child: Center( | |
child: Text(title), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment