Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
first-flutter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kim hakjun
first-flutter
Commits
d0a10671
Commit
d0a10671
authored
1 year ago
by
kim hakjun
Browse files
Options
Downloads
Patches
Plain Diff
7 stage
parent
8c300b27
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/main.dart
+88
-33
88 additions, 33 deletions
lib/main.dart
with
88 additions
and
33 deletions
lib/main.dart
+
88
−
33
View file @
d0a10671
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 {
),
),
],
],
),
),
),
);
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment