Skip to content
Snippets Groups Projects
Select Git revision
  • a274c456e7f579fd06ade5930373127c42234722
  • master default protected
  • 77-improve-app-metadata
  • 68-add-words
  • 62-fix-get-image-when-word-with-accent
  • 44-implement-game-write-word-from-letters
  • 43-add-script-to-get-images-from-assets
  • 32-add-accents-and-diacritics-in-french-words-2
  • Release_0.10.1_81 protected
  • Release_0.10.0_80 protected
  • Release_0.9.2_79 protected
  • Release_0.9.1_78 protected
  • Release_0.9.0_77 protected
  • Release_0.8.0_76 protected
  • Release_0.7.0_75 protected
  • Release_0.6.0_74 protected
  • Release_0.5.2_73 protected
  • Release_0.5.1_72 protected
  • Release_0.5.0_71 protected
  • Release_0.4.1_70 protected
  • Release_0.4.0_69 protected
  • Release_0.3.1_68 protected
  • Release_0.3.0_67 protected
  • Release_0.2.1_66 protected
  • Release_0.2.0_65 protected
  • Release_0.1.40_64 protected
  • Release_0.1.39_63 protected
  • Release_0.1.38_62 protected
28 results

page_settings.dart

Blame
  • home.dart 6.06 KiB
    import 'package:flutter/material.dart';
    import 'package:provider/provider.dart';
    
    import 'dart:math';
    import 'dart:async';
    
    import '../provider/data.dart';
    import '../utils/random_pick_category.dart';
    import '../utils/random_pick_letter.dart';
    
    class Home extends StatelessWidget {
      static const String id = 'home';
    
      String _randomLetter = '';
      String _randomCategory = '';
      Timer _timer;
      int _countdownStart = 10;
    
      Future<void> startMiniGame(Data myProvider) async {
        if (myProvider.countdown == 0) {
          pickCategory(myProvider);
          pickLetter(myProvider);
          startTimer(myProvider);
        }
      }
    
      Future<void> startTimer(Data myProvider) async {
        const oneSec = const Duration(seconds: 1);
        if (_timer != null) {
          dispose();
        }
        _countdownStart = 10;
        myProvider.updateCountdown = _countdownStart;
        _timer = new Timer.periodic(
          oneSec,
          (Timer timer) {
            if (_countdownStart == 0) {
              timer.cancel();
            } else {
              _countdownStart--;
              myProvider.updateCountdown = _countdownStart;
            }
          },
        );
      }
    
      @override
      void dispose() {
        _timer.cancel();
      }
    
      Future<void> pickCategory(Data myProvider) async {
        myProvider.searchingCategory = true;
        RandomPickCategory randomPickCategory;
        int attempts = 0;
        do {
          randomPickCategory = RandomPickCategory();
          await randomPickCategory.init();
          if (randomPickCategory.category != null) {
            myProvider.updateCategory = randomPickCategory.category;
            myProvider.searchingCategory = false;
            break;
          }
          attempts++;
        } while (attempts < 3);
      }
    
      Future<void> pickLetter(Data myProvider) async {
        myProvider.searchingLetter = true;
        RandomPickLetter randomPickLetter;