Skip to content
Snippets Groups Projects
Commit d18dda1f authored by wonbin's avatar wonbin
Browse files

myflutter

parent af2865a0
No related branches found
No related tags found
No related merge requests found
......@@ -47,20 +47,50 @@ class MyAppState extends ChangeNotifier {
// ...
// ...
// ...
// ...
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
// ...
class _MyHomePageState extends State<MyHomePage> {
var selectedIndex = 0; // ← Add this property.
@override
Widget build(BuildContext context) {
// ...
Widget page;
switch (selectedIndex) {
case 0:
page = GeneratorPage();
break;
case 1:
page = FavoritesPage();
break;
default:
throw UnimplementedError('no widget for $selectedIndex');
}
// ...
return LayoutBuilder(
builder: (context,constrains) {
return Scaffold(
body: Row(
children: [
SafeArea(
child: NavigationRail(
extended: false,
extended: constrains.maxWidth >= 600,
destinations: [
NavigationRailDestination(
icon: Icon(Icons.home),
......@@ -71,24 +101,33 @@ class _MyHomePageState extends State<MyHomePage> {
label: Text('Favorites'),
),
],
selectedIndex: 0,
selectedIndex: selectedIndex, // ← Change to this.
onDestinationSelected: (value) {
print('selected: $value');
// ↓ Replace print with this.
setState(() {
selectedIndex = value;
});
},
),
),
Expanded(
child: Container(
color: Theme.of(context).colorScheme.primaryContainer,
child: GeneratorPage(),
child: page,
),
),
],
),
);
}
);
}
}
// ...
class GeneratorPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
......@@ -135,6 +174,37 @@ class GeneratorPage extends StatelessWidget {
// ...
class FavoritesPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
if (appState.favorites.isEmpty) {
return Center(
child: Text('No favorites yet.'),
);
}
return ListView(
children: [
Padding(
padding: const EdgeInsets.all(20),
child: Text('You have '
'${appState.favorites.length} favorites:'),
),
for (var pair in appState.favorites)
ListTile(
leading: Icon(Icons.favorite),
title: Text(pair.asLowerCase),
),
],
);
}
}
// ...
// ...
// ...
class BigCard extends StatelessWidget {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment