From 3ee73c301a9afd43915c2de5af6e5c03d2d35b00 Mon Sep 17 00:00:00 2001 From: Ibraheem Saleh Date: Sun, 31 Mar 2024 18:49:50 -0700 Subject: [PATCH] Add complete impl from codelabs github --- lib/main.dart | 126 +++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 64 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index f875ee4..fadf01d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -43,7 +43,6 @@ class MyAppState extends ChangeNotifier { } notifyListeners(); } - } class MyHomePage extends StatefulWidget { @@ -63,41 +62,44 @@ class _MyHomePageState extends State { case 1: page = FavoritesPage(); default: - throw UnimplementedError('Unknown index: $selectedIndex'); + throw UnimplementedError('no widget for $selectedIndex'); } - return Scaffold( - body: Row( - children: [ - SafeArea( - child: NavigationRail( - extended: false, - destinations: [ - NavigationRailDestination( - icon: Icon(Icons.home), - label: Text('Home'), - ), - NavigationRailDestination( - icon: Icon(Icons.favorite), - label: Text('Favorites'), - ), - ], - selectedIndex: selectedIndex, - onDestinationSelected: (value) { - setState(() { - selectedIndex = value; - }); - }, + + 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, + Expanded( + child: Container( + color: Theme.of(context).colorScheme.primaryContainer, + child: page, + ), ), - ), - ], - ), - ); + ], + ), + ); + }); } } @@ -145,7 +147,34 @@ class GeneratorPage extends StatelessWidget { } } +class BigCard extends StatelessWidget { + const BigCard({ + super.key, + required this.pair, + }); + + final WordPair pair; + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final style = theme.textTheme.displayMedium!.copyWith( + color: theme.colorScheme.onPrimary, + ); + + return Card( + color: theme.colorScheme.primary, + child: Padding( + padding: const EdgeInsets.all(20), + child: Text( + pair.asLowerCase, + style: style, + semanticsLabel: "${pair.first} ${pair.second}", + ), + ), + ); + } +} class FavoritesPage extends StatelessWidget { @override @@ -174,34 +203,3 @@ class FavoritesPage extends StatelessWidget { ); } } - - - -class BigCard extends StatelessWidget { - const BigCard({ - super.key, - required this.pair, - }); - - final WordPair pair; - - @override - Widget build(BuildContext context) { - var theme = Theme.of(context); - var style = theme.textTheme.displayMedium!.copyWith( - color: theme.colorScheme.onPrimary, - ); - - return Card( - color: theme.colorScheme.primary, - child: Padding( - padding: const EdgeInsets.all(20), - child: Text( - pair.asLowerCase, - style: style, - semanticsLabel: pair.asPascalCase, - ), - ), - ); - } -}