From e1d051c1df8244c7d9ed4eb80ef0b49c4036d372 Mon Sep 17 00:00:00 2001 From: Jingeun Lee <exploitsori@ajou.ac.kr> Date: Wed, 16 Apr 2025 18:47:35 +0900 Subject: [PATCH] =?UTF-8?q?7.=20=ED=83=90=EC=83=89=20=EB=A0=88=EC=9D=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 118 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 89 insertions(+), 29 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index ac9092a..4e9edf3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -44,7 +44,69 @@ 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>(); @@ -57,34 +119,32 @@ class MyHomePage extends StatelessWidget { icon = Icons.favorite_border; } - return Scaffold( - body: 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'), - ), - ], - ), - ], - ), + 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'), + ), + ], + ), + ], ), ); } -- GitLab