diff --git a/lib/main.dart b/lib/main.dart index b90f1edf760aa95cb7e941fc13b9c544222540ce..391343ba790ffc7ebe3f2f175350d3b7df59180d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -46,43 +46,149 @@ class MyAppState extends ChangeNotifier { } } -class MyHomePage extends StatelessWidget { +class MyHomePage extends StatefulWidget { + @override + State<MyHomePage> createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State<MyHomePage> { + + var selectedIndex = 0; + + @override + Widget build(BuildContext context) { + Widget page; + switch (selectedIndex){ + case 0: + page = GeneratorPage(); + break; + case 1: + page = Placeholder(); + break; + default: + throw UnimplementedError('no widget for $selectedIndex'); + } + return LayoutBuilder( + builder: (context, constraints) { + return Scaffold( + body: Row( + children: [ + SafeArea( + child: NavigationRail( + extended: constraints.maxWidth >= 600, + destinations: [ + NavigationRailDestination( + icon: Icon(Icons.home), + label: Text('Home'), + ), + NavigationRailDestination( + icon: Icon(Icons.favorite), + label: Text('Favorites'), + ), + ], + selectedIndex: selectedIndex, + onDestinationSelected: (value) { + setState(() { + selectedIndex = value; + }); + }, + ), + ), + Expanded( + child: Container( + color: Theme.of(context).colorScheme.primaryContainer, + child: page, + ), + ), + ], + ), + ); + } + ); + } +} + +class GeneratorPage extends StatelessWidget { @override Widget build(BuildContext context) { var appState = context.watch<MyAppState>(); var pair = appState.current; IconData icon; - if(appState.favorites.contains(pair)){ + if (appState.favorites.contains(pair)) { icon = Icons.favorite; - } - else{ + } else { icon = Icons.favorite_border; } - return Scaffold( - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - // Text('A random AWESOME idea:'), - BigCard(pair: pair), - SizedBox(height: 10,), - Row( - mainAxisSize: MainAxisSize.min, - children: [ - ElevatedButton.icon(onPressed: (){appState.toggleFavorite();}, icon:Icon(icon), label: Text('Like'),), - SizedBox(width: 10,), - ElevatedButton(onPressed: (){appState.getNext();}, child: Text('Next'),), - ], - ), - ], - ), + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + BigCard(pair: pair), + SizedBox(height: 10), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + ElevatedButton.icon( + onPressed: () { + appState.toggleFavorite(); + }, + icon: Icon(icon), + label: Text('Like'), + ), + SizedBox(width: 10), + ElevatedButton( + onPressed: () { + appState.getNext(); + }, + child: Text('Next'), + ), + ], + ), + ], ), ); } } +// class MyHomePage extends StatelessWidget { +// @override +// Widget build(BuildContext context) { +// var appState = context.watch<MyAppState>(); +// var pair = appState.current; + +// IconData icon; +// if(appState.favorites.contains(pair)){ +// icon = Icons.favorite; +// } +// else{ +// icon = Icons.favorite_border; +// } + +// return Scaffold( +// body: Center( +// child: Column( +// mainAxisAlignment: MainAxisAlignment.center, +// children: [ +// // Text('A random AWESOME idea:'), +// BigCard(pair: pair), +// SizedBox(height: 10,), +// Row( +// mainAxisSize: MainAxisSize.min, +// children: [ +// ElevatedButton.icon(onPressed: (){appState.toggleFavorite();}, icon:Icon(icon), label: Text('Like'),), +// SizedBox(width: 10,), +// ElevatedButton(onPressed: (){appState.getNext();}, child: Text('Next'),), +// ], +// ), +// ], +// ), +// ), +// ); +// } +// } + class BigCard extends StatelessWidget { const BigCard({ super.key,