Skip to content
Snippets Groups Projects
Select Git revision
  • dc0ec6ee84e92c609bdda53970ad798b968a4183
  • master default protected
  • 47-upgrade-framework-and-dependencies
  • 21-improve-app-metadata
  • Release_0.9.0_40 protected
  • Release_0.8.2_39 protected
  • Release_0.8.1_38 protected
  • Release_0.8.0_37 protected
  • Release_0.7.0_36 protected
  • Release_0.6.0_35 protected
  • Release_0.5.0_34 protected
  • Release_0.4.2_33 protected
  • Release_0.4.1_32 protected
  • Release_0.4.0_31 protected
  • Release_0.3.1_30 protected
  • Release_0.3.0_29 protected
  • Release_0.2.1_28 protected
  • Release_0.2.0_27 protected
  • Release_0.1.2_26 protected
  • Release_0.1.1_25 protected
  • Release_0.1.0_24 protected
  • Release_0.0.23_23 protected
  • Release_0.0.22_22 protected
  • Release_0.0.21_21 protected
24 results

default_game_settings.dart

Blame
  • game_pick_word.dart 5.19 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 pickWord(context, myProvider);
        await pickImage(context, myProvider, myProvider.word);
      }
    
      Future<void> pickWord(BuildContext context, Data myProvider) async {
        List words;
        RandomPickWord randomPickWord;
        int attempts = 0;
        do {
          randomPickWord = RandomPickWord();
          await randomPickWord.init(_count);
          if (randomPickWord.words != null) {
            words = randomPickWord.words;
            break;
          }
          attempts++;
        } while (attempts < 3);
    
        if ((words != null) && (words.length == _count)) {
          myProvider.updateWord = words.take(1).toList()[0];
          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;
        }
      }
    
      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,
            child: Image(image: AssetImage(imageAsset)),
          ),
        );
      }