Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
org.benoitharrault.wordguessing
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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
org.benoitharrault.wordguessing
Commits
5636e82c
Commit
5636e82c
authored
4 years ago
by
Benoît Harrault
Browse files
Options
Downloads
Patches
Plain Diff
Add game "pick image from word"
parent
b52381b2
No related branches found
No related tags found
1 merge request
!39
Resolve "Add game "pick image from word""
Pipeline
#1118
passed
4 years ago
Stage: update
Stage: build-debug
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
android/gradle.properties
+2
-2
2 additions, 2 deletions
android/gradle.properties
lib/main.dart
+8
-0
8 additions, 0 deletions
lib/main.dart
lib/screens/game_pick_image.dart
+306
-0
306 additions, 0 deletions
lib/screens/game_pick_image.dart
lib/screens/home.dart
+17
-0
17 additions, 0 deletions
lib/screens/home.dart
with
333 additions
and
2 deletions
android/gradle.properties
+
2
−
2
View file @
5636e82c
org.gradle.jvmargs
=
-Xmx1536M
android.useAndroidX
=
true
android.enableJetifier
=
true
app.versionName
=
0.1.
9
app.versionCode
=
3
3
app.versionName
=
0.1.
10
app.versionCode
=
3
4
This diff is collapsed.
Click to expand it.
lib/main.dart
+
8
−
0
View file @
5636e82c
...
...
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import
'provider/data.dart'
;
import
'screens/home.dart'
;
import
'screens/game_pick_word.dart'
;
import
'screens/game_pick_image.dart'
;
void
main
()
{
WidgetsFlutterBinding
.
ensureInitialized
();
...
...
@@ -35,6 +36,13 @@ class MyApp extends StatelessWidget {
}
break
;
case
'/game-pick-image'
:
{
return
MaterialPageRoute
(
builder:
(
context
)
=
>
GamePickImagePage
(),
);
}
break
;
default
:
{
print
(
"Unknown menu entry"
);
}
break
;
}
...
...
This diff is collapsed.
Click to expand it.
lib/screens/game_pick_image.dart
0 → 100644
+
306
−
0
View file @
5636e82c
import
'package:flutter/material.dart'
;
import
'package:provider/provider.dart'
;
import
'../provider/data.dart'
;
import
'../utils/random_pick_data.dart'
;
class
GamePickImagePage
extends
StatelessWidget
{
int
_countWords
=
4
;
int
_countImages
=
1
;
Future
<
void
>
startGame
(
Data
myProvider
,
String
lang
)
async
{
await
resetGame
(
myProvider
);
myProvider
.
updateLang
=
lang
;
await
nextWord
(
myProvider
);
}
Future
<
void
>
resetGame
(
Data
myProvider
)
async
{
myProvider
.
updateLang
=
''
;
myProvider
.
updateQuestionsCount
=
0
;
myProvider
.
updateGoodAnswers
=
0
;
myProvider
.
updateWrongAnswers
=
0
;
myProvider
.
updateWord
=
null
;
myProvider
.
updateImages
=
null
;
}
Future
<
void
>
nextWord
(
Data
myProvider
)
async
{
await
pickData
(
myProvider
);
myProvider
.
updateQuestionsCount
=
myProvider
.
questionsCount
+
1
;
}
Future
<
void
>
pickData
(
Data
myProvider
)
async
{
List
words
;
RandomPickData
randomPickData
;
Map
word
;
int
attempts
=
0
;
do
{
randomPickData
=
RandomPickData
();
await
randomPickData
.
init
(
myProvider
.
lang
,
_countWords
,
_countImages
);
if
(
randomPickData
.
words
!=
null
)
{
words
=
randomPickData
.
words
;
word
=
words
.
take
(
1
)
.
toList
()[
0
];
}
attempts
++
;
}
while
(
attempts
<
3
);
if
((
words
!=
null
)
&&
(
words
.
length
==
_countWords
))
{
myProvider
.
updateWord
=
word
;
myProvider
.
updateImages
=
words
;
}
}
Future
<
void
>
checkWord
(
Data
myProvider
,
word
)
async
{
if
(
myProvider
.
word
[
'key'
]
==
word
[
'key'
])
{
myProvider
.
updateGoodAnswers
=
myProvider
.
goodAnswers
+
1
;
nextWord
(
myProvider
);
}
else
{
myProvider
.
updateWrongAnswers
=
myProvider
.
wrongAnswers
+
1
;
}
}
Container
_buildScoreItemContainer
(
String
text
,
Color
blockColor
)
{
Color
backgroundColor
=
blockColor
;
// Darken block color to get border color
double
amount
=
0.2
;
final
hsl
=
HSLColor
.
fromColor
(
blockColor
);
final
hslDark
=
hsl
.
withLightness
((
hsl
.
lightness
-
amount
)
.
clamp
(
0.0
,
1.0
));
Color
borderColor
=
hslDark
.
toColor
();
return
Container
(
margin:
EdgeInsets
.
symmetric
(
horizontal:
15
),
padding:
EdgeInsets
.
all
(
5
),
decoration:
BoxDecoration
(
color:
backgroundColor
,
borderRadius:
BorderRadius
.
circular
(
4
),
border:
Border
.
all
(
color:
borderColor
,
width:
4
,
),
),
child:
Text
(
text
,
style:
TextStyle
(
fontSize:
25
,
fontWeight:
FontWeight
.
w600
,
color:
Colors
.
black
,
),
),
);
}
Container
_buildScoreContainer
(
Data
myProvider
)
{
return
Container
(
padding:
EdgeInsets
.
all
(
5
),
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
_buildScoreItemContainer
(
'❓ '
+
myProvider
.
questionsCount
.
toString
(),
Colors
.
white
,
),
SizedBox
(
width:
20
),
_buildScoreItemContainer
(
'☺️ '
+
myProvider
.
goodAnswers
.
toString
(),
Colors
.
green
,
),
SizedBox
(
width:
20
),
_buildScoreItemContainer
(
'😟 '
+
myProvider
.
wrongAnswers
.
toString
(),
Colors
.
orange
,
),
],
),
);
}
Container
_buildImageContainer
(
Data
myProvider
,
Map
word
)
{
double
imageSize
=
130
;
String
imageAsset
=
'assets/placeholder.png'
;
if
((
word
[
'images'
]
!=
null
)
&&
(
word
[
'images'
][
0
]
!=
null
))
{
imageAsset
=
'assets/images/'
+
word
[
'images'
][
0
];
}
return
Container
(
child:
FlatButton
(
child:
Container
(
decoration:
BoxDecoration
(
borderRadius:
BorderRadius
.
circular
(
8
),
border:
Border
.
all
(
color:
Colors
.
teal
,
width:
8
,
),
),
margin:
EdgeInsets
.
all
(
2
),
child:
Image
(
image:
AssetImage
(
imageAsset
),
width:
imageSize
,
height:
imageSize
,
fit:
BoxFit
.
fill
),
),
onPressed:
()
{
checkWord
(
myProvider
,
word
);
},
),
);
}
Column
_buildImageItemsBlock
(
Data
myProvider
)
{
List
words
=
myProvider
.
images
;
if
((
words
==
null
)
||
(
words
.
length
!=
_countWords
))
{
return
Column
();
}
words
.
sort
((
a
,
b
)
=
>
a
[
'key'
]
.
compareTo
(
b
[
'key'
]));
return
Column
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Row
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
_buildImageContainer
(
myProvider
,
words
[
0
]),
_buildImageContainer
(
myProvider
,
words
[
1
]),
],
),
Row
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
_buildImageContainer
(
myProvider
,
words
[
2
]),
_buildImageContainer
(
myProvider
,
words
[
3
]),
],
)
],
);
}
Column
_buildTextItemBlock
(
Data
myProvider
)
{
Map
word
=
myProvider
.
word
;
if
(
word
==
null
)
{
return
Column
();
}
return
Column
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Container
(
margin:
EdgeInsets
.
all
(
2
),
decoration:
BoxDecoration
(
borderRadius:
BorderRadius
.
circular
(
6
),
border:
Border
.
all
(
color:
Colors
.
white
,
width:
6
,
),
),
child:
RaisedButton
(
color:
Colors
.
green
,
padding:
EdgeInsets
.
all
(
15
),
child:
Text
(
word
!=
null
?
word
[
myProvider
.
lang
]
:
''
,
style:
TextStyle
(
fontSize:
30
,
fontWeight:
FontWeight
.
w600
,
color:
Colors
.
white
,
),
),
),
),
],
);
}
Column
_buildStartGameBlock
(
Data
myProvider
)
{
return
Column
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Container
(
child:
RaisedButton
(
color:
Colors
.
teal
,
padding:
EdgeInsets
.
all
(
35
),
child:
Text
(
"🇫🇷"
,
style:
TextStyle
(
fontSize:
60
,
color:
Colors
.
black
,
),
),
onPressed:
()
=
>
startGame
(
myProvider
,
'fr'
),
),
),
SizedBox
(
height:
15
),
Container
(
child:
RaisedButton
(
color:
Colors
.
teal
,
padding:
EdgeInsets
.
all
(
35
),
child:
Text
(
"🇬🇧"
,
style:
TextStyle
(
fontSize:
60
,
color:
Colors
.
black
,
),
),
onPressed:
()
=
>
startGame
(
myProvider
,
'en'
),
),
)
],
);
}
@override
Widget
build
(
BuildContext
context
)
{
Data
_myProvider
=
Provider
.
of
<
Data
>(
context
);
Scaffold
pageContent
=
Scaffold
(
appBar:
AppBar
(
elevation:
0
,
actions:
<
Widget
>[
IconButton
(
icon:
const
Icon
(
Icons
.
loop
),
onPressed:
()
=
>
resetGame
(
_myProvider
),
),
],
),
backgroundColor:
Colors
.
blue
,
body:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisSize:
MainAxisSize
.
max
,
children:
<
Widget
>[
_buildTextItemBlock
(
_myProvider
),
SizedBox
(
height:
2
),
((
_myProvider
.
word
==
null
)
||
(
_myProvider
.
word
[
'key'
]
==
''
))
?
_buildStartGameBlock
(
_myProvider
)
:
_buildScoreContainer
(
_myProvider
),
SizedBox
(
height:
2
),
_buildImageItemsBlock
(
_myProvider
),
],
),
),
);
return
SizedBox
.
expand
(
child:
Container
(
child:
FittedBox
(
fit:
BoxFit
.
contain
,
alignment:
Alignment
.
center
,
child:
SizedBox
(
height:
(
MediaQuery
.
of
(
context
)
.
size
.
height
),
width:
(
MediaQuery
.
of
(
context
)
.
size
.
width
),
child:
pageContent
,
)
)
)
);
}
}
This diff is collapsed.
Click to expand it.
lib/screens/home.dart
+
17
−
0
View file @
5636e82c
...
...
@@ -35,6 +35,23 @@ class Home extends StatelessWidget {
);
},
),
FlatButton
(
color:
Colors
.
green
,
padding:
EdgeInsets
.
all
(
15
),
child:
Text
(
'💬️ ➡️ 🖼'
,
style:
Theme
.
of
(
context
)
.
textTheme
.
display1
.
copyWith
(
color:
Colors
.
white
),
),
onPressed:
()
{
Navigator
.
pushNamed
(
context
,
'/game-pick-image'
,
);
},
),
],
),
),
...
...
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