aboutsummaryrefslogtreecommitdiffstats
path: root/lib/screens/loading_screen.dart
blob: f4d6c6d9e13f9fc84714ef3629571c61e3fe805a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter_voiceassistant/screens/home_screen.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../models/app_state.dart';
import '../utils/app_config.dart';

class Loading extends StatelessWidget {
  final AppConfig config;
  final String wakeWord;
  Loading({required this.config, required this.wakeWord});

  Future<void> initialize(BuildContext context) async {
    // Initialize the app
    final appState = context.read<AppState>();
    bool isWakeWordMode = false;
    String intentEngine = "snips";
    String streamId = "";
    bool isCommandProcessing = false;
    String commandProcessingText = "Processing...";
    String sttFramework = "vosk";
    bool onlineMode = false;

    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.reload();
    if(prefs.containsKey('isWakeWordMode')) {
      isWakeWordMode = await prefs.getBool('isWakeWordMode')!;
    }
    if(prefs.containsKey('intentEngine')) {
      intentEngine = await prefs.getString('intentEngine')!;
    }
    if(prefs.containsKey('streamId')) {
      streamId = await prefs.getString('streamId')!;
    }
    if(prefs.containsKey('isCommandProcessing')) {
      isCommandProcessing = await prefs.getBool('isCommandProcessing')!;
    }
    if(prefs.containsKey('commandProcessingText')) {
      commandProcessingText = await prefs.getString('commandProcessingText')!;
    }
    if(prefs.containsKey('sttFramework')) {
      sttFramework = await prefs.getString('sttFramework')!;
    }
    if(prefs.containsKey('onlineMode')) {
      onlineMode = await prefs.getBool('onlineMode')!;
    }

    appState.isWakeWordMode = isWakeWordMode;
    appState.intentEngine = intentEngine;
    appState.streamId = streamId;
    appState.isCommandProcessing = isCommandProcessing;
    appState.commandProcessingText = commandProcessingText;
    appState.sttFramework = sttFramework;
    appState.onlineMode = onlineMode;

    print('isWakeWordMode: $isWakeWordMode');
    print('intentEngine: $intentEngine');
    print('streamId: $streamId');
    print('isCommandProcessing: $isCommandProcessing');
    print('commandProcessingText: $commandProcessingText');
    print('sttFramework: $sttFramework');
    print('onlineMode: $onlineMode');
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: initialize(context),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          return HomePage(config: config, wakeWord: wakeWord);
        } else {
          return CupertinoActivityIndicator();
        }
      },
    );
  }
}