Skip to content
Snippets Groups Projects
Select Git revision
  • 48f25e351686878bc69e5e8f24173a9f581f6a2b
  • master default protected
  • 84-improve-app-metadata
  • 82-fix-colors
  • 23-add-timer
  • 65-update-icons
  • Release_0.10.1_88 protected
  • Release_0.10.0_87 protected
  • Release_0.9.2_86 protected
  • Release_0.9.1_85 protected
  • Release_0.9.0_84 protected
  • Release_0.8.0_83 protected
  • Release_0.7.0_82 protected
  • Release_0.6.0_81 protected
  • Release_0.5.2_80 protected
  • Release_0.5.1_79 protected
  • Release_0.5.0_78 protected
  • Release_0.4.1_77 protected
  • Release_0.4.0_76 protected
  • Release_0.3.1_75 protected
  • Release_0.3.0_74 protected
  • Release_0.2.1_73 protected
  • Release_0.2.0_72 protected
  • Release_0.1.22_71 protected
  • Release_0.1.21_70 protected
  • Release_0.1.20_69 protected
26 results

board.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;