Add navigation with expanding sidebar.
This commit is contained in:
parent
082dff1810
commit
ab0b551a64
@ -46,7 +46,71 @@ 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var appState = context.watch<MyAppState>();
|
var appState = context.watch<MyAppState>();
|
||||||
@ -59,36 +123,32 @@ class MyHomePage extends StatelessWidget {
|
|||||||
icon = Icons.favorite_border;
|
icon = Icons.favorite_border;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Center(
|
||||||
body: Center(
|
child: Column(
|
||||||
child: Column(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
children: [
|
||||||
children: [
|
BigCard(pair: pair),
|
||||||
BigCard(pair: pair),
|
SizedBox(height: 10),
|
||||||
SizedBox(height: 10.0), // Just a spacer.
|
Row(
|
||||||
Row(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
children: [
|
||||||
children: [
|
ElevatedButton.icon(
|
||||||
ElevatedButton.icon(
|
onPressed: () {
|
||||||
onPressed: () {
|
appState.toggleFavorite();
|
||||||
appState.toggleFavorite();
|
},
|
||||||
},
|
icon: Icon(icon),
|
||||||
icon: Icon(icon),
|
label: Text('Like'),
|
||||||
label: Text('Favorite'),
|
),
|
||||||
),
|
SizedBox(width: 10),
|
||||||
|
ElevatedButton(
|
||||||
SizedBox(width: 10.0),
|
onPressed: () {
|
||||||
|
appState.getNext();
|
||||||
ElevatedButton(
|
},
|
||||||
onPressed: () {
|
child: Text('Next'),
|
||||||
appState.getNext();
|
),
|
||||||
},
|
],
|
||||||
child: Text('Next'),
|
),
|
||||||
),
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user