Skip to content
Snippets Groups Projects
Select Git revision
  • 362e9a7e662d3747c6cdcb33db8a472df6674e5b
  • master default protected
  • 49-upgrade-framework-and-dependencies
  • 32-improve-app-metadata
  • Release_0.9.0_43 protected
  • Release_0.8.2_42 protected
  • Release_0.8.1_41 protected
  • Release_0.8.0_40 protected
  • Release_0.7.0_39 protected
  • Release_0.6.0_38 protected
  • Release_0.5.0_37 protected
  • Release_0.4.2_36 protected
  • Release_0.4.1_35 protected
  • Release_0.4.0_34 protected
  • Release_0.3.1_33 protected
  • Release_0.3.0_32 protected
  • Release_0.2.1_31 protected
  • Release_0.2.0_30 protected
  • Release_0.1.2_29 protected
  • Release_0.1.1_28 protected
  • Release_0.1.0_27 protected
  • Release_0.0.26_26 protected
  • Release_0.0.25_25 protected
  • Release_0.0.24_24 protected
24 results

parameter_painter.dart

Blame
  • game_pick_word.dart 6.87 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 {
        myProvider.updateQuestionsCount = 0;
        myProvider.updateGoodAnswers = 0;
        myProvider.updateWrongAnswers = 0;
        await nextWord(context, myProvider);
      }
    
      Future<void> nextWord(BuildContext context, Data myProvider) async {
        await pickData(context, myProvider);
        myProvider.updateQuestionsCount = myProvider.questionsCount + 1;
      }
    
      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) {
          myProvider.updateGoodAnswers = myProvider.goodAnswers + 1;
          nextWord(context, myProvider);
        } else {
          myProvider.updateWrongAnswers = myProvider.wrongAnswers + 1;
        }
      }
    
      Container _buildScoreContainer(BuildContext context, Data myProvider) {
        String score = ''
          + '❓ ' + myProvider.questionsCount.toString()