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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
org.benoitharrault.wordguessing
Commits
ad7413d3
Commit
ad7413d3
authored
4 years ago
by
Benoît Harrault
Browse files
Options
Downloads
Patches
Plain Diff
Improve get random words and images
parent
1e507b03
No related branches found
No related tags found
1 merge request
!42
Resolve "Improve code to get random words and images"
Pipeline
#1116
passed
4 years ago
Stage: update
Stage: build-debug
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
android/gradle.properties
+2
-2
2 additions, 2 deletions
android/gradle.properties
lib/screens/game_pick_word.dart
+13
-19
13 additions, 19 deletions
lib/screens/game_pick_word.dart
lib/utils/random_pick_data.dart
+45
-0
45 additions, 0 deletions
lib/utils/random_pick_data.dart
with
60 additions
and
21 deletions
android/gradle.properties
+
2
−
2
View file @
ad7413d3
org.gradle.jvmargs
=
-Xmx1536M
android.useAndroidX
=
true
android.enableJetifier
=
true
app.versionName
=
0.1.
8
app.versionCode
=
3
2
app.versionName
=
0.1.
9
app.versionCode
=
3
3
This diff is collapsed.
Click to expand it.
lib/screens/game_pick_word.dart
+
13
−
19
View file @
ad7413d3
...
...
@@ -2,11 +2,11 @@ import 'package:flutter/material.dart';
import
'package:provider/provider.dart'
;
import
'../provider/data.dart'
;
import
'../utils/random_pick_word.dart'
;
import
'../utils/random_pick_image.dart'
;
import
'../utils/random_pick_data.dart'
;
class
GamePickWordPage
extends
StatelessWidget
{
int
_count
=
4
;
int
_countWords
=
4
;
int
_countImages
=
4
;
Future
<
void
>
startGame
(
Data
myProvider
,
String
lang
)
async
{
await
resetGame
(
myProvider
);
...
...
@@ -31,32 +31,26 @@ class GamePickWordPage extends StatelessWidget {
Future
<
void
>
pickData
(
Data
myProvider
)
async
{
List
words
;
List
images
;
RandomPickWord
randomPickWord
;
RandomPickImage
randomPickImage
;
RandomPickData
randomPickData
;
Map
word
;
int
attempts
=
0
;
do
{
randomPick
Word
=
RandomPick
Word
();
await
randomPick
Word
.
init
(
myProvider
.
lang
,
_count
);
randomPick
Data
=
RandomPick
Data
();
await
randomPick
Data
.
init
(
myProvider
.
lang
,
_count
Words
,
_countImages
);
if
(
randomPick
Word
.
words
!=
null
)
{
words
=
randomPick
Word
.
words
;
if
(
randomPick
Data
.
words
!=
null
)
{
words
=
randomPick
Data
.
words
;
word
=
words
.
take
(
1
)
.
toList
()[
0
];
randomPickImage
=
RandomPickImage
();
await
randomPickImage
.
init
(
word
[
'key'
],
_count
);
if
(
randomPickImage
.
images
!=
null
)
{
images
=
randomPickImage
.
images
;
break
;
}
images
=
word
[
'images'
];
}
attempts
++
;
}
while
(
attempts
<
3
);
if
(
((
words
!=
null
)
&&
(
words
.
length
==
_count
))
((
words
!=
null
)
&&
(
words
.
length
==
_count
Words
))
&&
((
images
!=
null
)
&&
(
images
.
length
==
_count
))
((
images
!=
null
)
&&
(
images
.
length
==
_count
Images
))
)
{
myProvider
.
updateWord
=
word
;
myProvider
.
updateOtherWords
=
words
.
skip
(
1
)
.
toList
();
...
...
@@ -157,7 +151,7 @@ class GamePickWordPage extends StatelessWidget {
}
Column
_buildImageItemsBlock
(
List
images
)
{
if
((
images
==
null
)
||
(
images
.
length
!=
_count
))
{
if
((
images
==
null
)
||
(
images
.
length
!=
_count
Images
))
{
return
Column
();
}
...
...
@@ -207,7 +201,7 @@ class GamePickWordPage extends StatelessWidget {
Map
word
=
myProvider
.
word
;
List
otherWords
=
myProvider
.
otherWords
;
if
((
word
==
null
)
||
(
otherWords
.
length
!=
(
_count
-
1
)))
{
if
((
word
==
null
)
||
(
otherWords
.
length
!=
(
_count
Words
-
1
)))
{
return
Column
();
}
...
...
This diff is collapsed.
Click to expand it.
lib/utils/random_pick_data.dart
0 → 100644
+
45
−
0
View file @
ad7413d3
import
'dart:async'
;
import
'dart:convert'
;
import
'package:flutter/services.dart'
;
import
'random_pick_word.dart'
;
import
'random_pick_image.dart'
;
class
RandomPickData
{
RandomPickData
();
List
_words
;
init
(
String
lang
,
int
wordsCount
,
int
imagesPerWordCount
)
async
{
_words
=
new
List
(
wordsCount
);
await
getWordsAndImages
(
lang
,
wordsCount
,
imagesPerWordCount
);
}
Future
<
void
>
getWordsAndImages
(
String
lang
,
int
wordsCount
,
int
imagesPerWordCount
)
async
{
RandomPickWord
randomPickWord
;
RandomPickImage
randomPickImage
;
List
pickedWords
;
randomPickWord
=
RandomPickWord
();
await
randomPickWord
.
init
(
lang
,
wordsCount
);
if
(
randomPickWord
.
words
!=
null
)
{
pickedWords
=
randomPickWord
.
words
;
for
(
var
i
=
0
;
i
<
pickedWords
.
length
;
i
++
)
{
Map
word
=
pickedWords
[
i
];
randomPickImage
=
RandomPickImage
();
await
randomPickImage
.
init
(
word
[
'key'
],
imagesPerWordCount
);
if
(
randomPickImage
.
images
!=
null
)
{
pickedWords
[
i
][
'images'
]
=
randomPickImage
.
images
;
}
}
}
_words
=
pickedWords
;
}
List
get
words
=
>
_words
;
}
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