Skip to content

Instantly share code, notes, and snippets.

@csells
Created September 30, 2020 20:42
Show Gist options
  • Select an option

  • Save csells/d43e6fc56e23478ef8ae7b212c713a4e to your computer and use it in GitHub Desktop.

Select an option

Save csells/d43e6fc56e23478ef8ae7b212c713a4e to your computer and use it in GitHub Desktop.
flutter-nav2-part3
class _ColorAppState extends State<ColorApp> {
Color _selectedColor;
List<Color> _colors = [Colors.red, Colors.green, Colors.blue];
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Color App',
home: Navigator(
// you can see and decide on every page in this list
pages: [
MaterialPage(
child: ColorListScreen(
colors: _colors,
onTapped: (color) => setState(() => _selectedColor = color),
),
),
if (_selectedColor != null) MaterialPage(child: ColorScreen(color: _selectedColor)),
],
onPopPage: (route, result) {
if (!route.didPop(result)) return false;
setState(() => _selectedColor = null);
return true;
},
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment