Skip to content
Snippets Groups Projects
Select Git revision
  • 1f2740c2e90aeea7dcd6ee9e8c62cb1954725dc1
  • master default protected
  • 44-improve-app-metadata
  • Release_0.10.1_58 protected
  • Release_0.10.0_57 protected
  • Release_0.9.2_56 protected
  • Release_0.9.1_55 protected
  • Release_0.9.0_54 protected
  • Release_0.8.0_53 protected
  • Release_0.7.0_52 protected
  • Release_0.6.0_51 protected
  • Release_0.5.3_50 protected
  • Release_0.5.2_49 protected
  • Release_0.5.1_48 protected
  • Release_0.5.0_47 protected
  • Release_0.4.1_46 protected
  • Release_0.4.0_45 protected
  • Release_0.3.1_44 protected
  • Release_0.3.0_43 protected
  • Release_0.2.1_42 protected
  • Release_0.2.0_41 protected
  • Release_0.1.19_40 protected
  • Release_0.1.18_39 protected
23 results

game.dart

Blame
  • random_pick_category.dart 783 B
    import 'dart:async';
    import 'dart:convert';
    import 'dart:math' show Random;
    
    import 'package:flutter/services.dart';
    
    class RandomPickCategory {
      RandomPickCategory();
    
      String? _category;
      final random = Random();
    
      init() async {
        await categoryFromLocalFile();
      }
    
      Future<void> categoryFromLocalFile() async {
        String jsonString;
        try {
          jsonString = await rootBundle.loadString('assets/files/categories-fr.json');
          final jsonResponse = await json.decode(jsonString);
          var categoryList = jsonResponse[jsonResponse.keys.toList().join()];
          _category = categoryList[random.nextInt(categoryList.length)];
        } catch (e) {
          _category = 'UNEXPECTED ERROR';
        }
      }
    
      String get category => (_category != null) ? _category.toString() : '';
    }