Skip to content
Snippets Groups Projects
Commit d0a10671 authored by kim hakjun's avatar kim hakjun
Browse files

7 stage

parent 8c300b27
Branches
No related tags found
No related merge requests found
import 'package:english_words/english_words.dart'; import 'package:english_words/english_words.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
void main() { void main() {
...@@ -46,13 +47,72 @@ class MyAppState extends ChangeNotifier { ...@@ -46,13 +47,72 @@ 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, // ← Here.
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>();
var pair = appState.current; var pair = appState.current;
// ↓ Add this.
IconData icon; IconData icon;
if (appState.favorites.contains(pair)) { if (appState.favorites.contains(pair)) {
icon = Icons.favorite; icon = Icons.favorite;
...@@ -60,8 +120,7 @@ class MyHomePage extends StatelessWidget { ...@@ -60,8 +120,7 @@ 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: [
...@@ -70,8 +129,6 @@ class MyHomePage extends StatelessWidget { ...@@ -70,8 +129,6 @@ class MyHomePage extends StatelessWidget {
Row( Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
// ↓ And this.
ElevatedButton.icon( ElevatedButton.icon(
onPressed: () { onPressed: () {
appState.toggleFavorite(); appState.toggleFavorite();
...@@ -80,7 +137,6 @@ class MyHomePage extends StatelessWidget { ...@@ -80,7 +137,6 @@ class MyHomePage extends StatelessWidget {
label: Text('Like'), label: Text('Like'),
), ),
SizedBox(width: 10), SizedBox(width: 10),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
appState.getNext(); appState.getNext();
...@@ -91,7 +147,6 @@ class MyHomePage extends StatelessWidget { ...@@ -91,7 +147,6 @@ class MyHomePage extends StatelessWidget {
), ),
], ],
), ),
),
); );
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment