From 3965e54ab5ab24d8b85d99652ffa33fbc9ec745f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Sun, 2 May 2021 17:11:34 +0200 Subject: [PATCH] Merge pick words and image (fix missing images for words) --- android/gradle.properties | 4 +-- lib/screens/game_pick_word.dart | 45 +++++++++++++++------------------ 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index cd2d833..30298b3 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.17 -app.versionCode=17 +app.versionName=0.0.18 +app.versionCode=18 diff --git a/lib/screens/game_pick_word.dart b/lib/screens/game_pick_word.dart index 1e1addb..237fc96 100644 --- a/lib/screens/game_pick_word.dart +++ b/lib/screens/game_pick_word.dart @@ -9,46 +9,41 @@ class GamePickWordPage extends StatelessWidget { int _count = 4; Future<void> startGame(BuildContext context, Data myProvider) async { - await pickWord(context, myProvider); - await pickImage(context, myProvider, myProvider.word); + await pickData(context, myProvider); } - Future<void> pickWord(BuildContext context, Data myProvider) async { + Future<void> pickData(BuildContext context, Data myProvider) async { List words; + List images; RandomPickWord randomPickWord; + RandomPickImage randomPickImage; + String word; + int attempts = 0; do { randomPickWord = RandomPickWord(); await randomPickWord.init(_count); + if (randomPickWord.words != null) { words = randomPickWord.words; - break; + word = words.take(1).toList()[0]; + randomPickImage = RandomPickImage(); + await randomPickImage.init(word, _count); + if (randomPickImage.images != null) { + images = randomPickImage.images; + break; + } } attempts++; } while (attempts < 3); - if ((words != null) && (words.length == _count)) { - myProvider.updateWord = words.take(1).toList()[0]; + if ( + ((words != null) && (words.length == _count)) + && + ((images != null) && (images.length == _count)) + ) { + myProvider.updateWord = word; myProvider.updateOtherWords = words.skip(1).toList(); - } - } - - Future<void> pickImage(BuildContext context, Data myProvider, String word) async { - List images; - RandomPickImage randomPickImage; - int attempts = 0; - do { - randomPickImage = RandomPickImage(); - await randomPickImage.init(word, _count); - if (randomPickImage.images != null) { - images = randomPickImage.images; - break; - } - attempts++; - } while (attempts < 3); - - - if ((images != null) && (images.length == _count)) { myProvider.updateImages = images; } } -- GitLab