Select Git revision
game_pick_word.dart
-
Benoît Harrault authoredBenoît Harrault authored
game_pick_word.dart 5.94 KiB
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../provider/data.dart';
import '../utils/random_pick_word.dart';
import '../utils/get_image_from_word.dart';
class GamePickWordPage extends StatelessWidget {
int _count = 4;
Future<void> startGame(BuildContext context, Data myProvider) async {
await pickData(context, myProvider);
}
Future<void> nextWord(BuildContext context, Data myProvider) async {
await pickData(context, myProvider);
}
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;
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))
&&
((images != null) && (images.length == _count))
) {
myProvider.updateWord = word;
myProvider.updateOtherWords = words.skip(1).toList();
myProvider.updateImages = images;
}
}
Future<void> checkWord(BuildContext context, Data myProvider, word) async {
if (myProvider.word == word) {
nextWord(context, myProvider);
}
}
Container _buildImageContainer(String image, Color color) {
String imageAsset = 'assets/placeholder.png';
if (image != null) {
imageAsset = 'assets/images/'+image;
}
return Container(
padding: EdgeInsets.all(5),
child: FlatButton(
color: Colors.teal,