Skip to content
Snippets Groups Projects
Select Git revision
  • 3862336fbd3fbbeb1f941ad2410491fa3ff04321
  • master default protected
  • 42-add-allowed-categories-in-settings-page
  • 44-improve-app-metadata
  • 23-add-tip-response-on-clic-on-button
  • Release_1.11.1_56 protected
  • Release_1.11.0_55 protected
  • Release_1.10.2_54 protected
  • Release_1.10.1_53 protected
  • Release_1.10.0_52 protected
  • Release_1.9.0_51 protected
  • Release_1.8.0_50 protected
  • Release_1.7.0_49 protected
  • Release_1.6.2_48 protected
  • Release_1.6.1_47 protected
  • Release_1.6.0_46 protected
  • Release_1.5.1_45 protected
  • Release_1.5.0_44 protected
  • Release_1.4.1_43 protected
  • Release_1.4.0_42 protected
  • Release_1.3.1_41 protected
  • Release_1.3.0_40 protected
  • Release_1.2.33_39 protected
  • Release_1.2.32_38 protected
  • Release_1.2.31_37 protected
25 results

random_pick_category.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() : '';
    }