Skip to content
Snippets Groups Projects
Select Git revision
  • 4264b5dd81bf7decd7e0376fc9613f4f8c3e6c42
  • master default protected
  • 24-add-fruits
  • 15-improve-app-metadata
  • Release_0.10.1_32 protected
  • Release_0.10.0_31 protected
  • Release_0.9.2_30 protected
  • Release_0.9.1_29 protected
  • Release_0.9.0_28 protected
  • Release_0.8.0_27 protected
  • Release_0.7.0_26 protected
  • Release_0.6.0_25 protected
  • Release_0.5.4_24 protected
  • Release_0.5.3_23 protected
  • Release_0.5.2_22 protected
  • Release_0.5.1_21 protected
  • Release_0.5.0_20 protected
  • Release_0.4.0_19 protected
  • Release_0.3.1_18 protected
  • Release_0.3.0_17 protected
  • Release_0.2.1_16 protected
  • Release_0.2.0_15 protected
  • Release_0.1.1_14 protected
  • Release_0.1.0_13 protected
24 results

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