Skip to content
Snippets Groups Projects
Select Git revision
  • b33877eeb59cb8398e064385af25a7dc2e86ed64
  • master default protected
  • 56-upgrade-framework-and-dependencies
  • 39-improve-app-metadata
  • 28-add-high-scores
  • 32-add-block-size-limit-parameter
  • 29-use-real-board-painter-to-draw-parameters-items
  • Release_0.9.0_47 protected
  • Release_0.8.2_46 protected
  • Release_0.8.1_45 protected
  • Release_0.8.0_44 protected
  • Release_0.7.0_43 protected
  • Release_0.6.0_42 protected
  • Release_0.5.0_41 protected
  • Release_0.4.2_40 protected
  • Release_0.4.1_39 protected
  • Release_0.4.0_38 protected
  • Release_0.3.1_37 protected
  • Release_0.3.0_36 protected
  • Release_0.2.1_35 protected
  • Release_0.2.0_34 protected
  • Release_0.1.1_33 protected
  • Release_0.1.0_32 protected
  • Release_0.0.31_31 protected
  • Release_0.0.30_30 protected
  • Release_0.0.29_29 protected
  • Release_0.0.28_28 protected
27 results

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)),
          ),
        );
      }