Skip to content

Instantly share code, notes, and snippets.

@stansidel
Created September 6, 2021 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stansidel/ba913bcc009066c1feb503345f0850f1 to your computer and use it in GitHub Desktop.
Save stansidel/ba913bcc009066c1feb503345f0850f1 to your computer and use it in GitHub Desktop.
Flutter Cupertino Basic Navigation
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