-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
52 lines (44 loc) · 1.64 KB
/
main.dart
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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:tflite/tflite.dart';
import 'dart:convert';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'config/router.dart';
import 'data_model/diagnosis.dart';
const history = "history";
late Box<Diagnosis> historyBox;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Tflite.loadModel(
model: "assets/model.tflite",
labels: "assets/labels.txt",
numThreads: 1, // defaults to 1
);
await Hive.initFlutter();
Hive.registerAdapter(DiagnosisAdapter());
//encryption of the hive storage
final FlutterSecureStorage secureStorage = FlutterSecureStorage();
var containsEncryptionKey = await secureStorage.containsKey(key: 'encryptionKey');
if (!containsEncryptionKey) {
var key = Hive.generateSecureKey();
await secureStorage.write(key: 'encryptionKey', value: base64UrlEncode(key));
}
var encryptionKey = base64Url.decode((await secureStorage.read(key: 'encryptionKey'))!);
//open the hive storage
historyBox = await Hive.openBox<Diagnosis>(history, encryptionCipher: HiveAesCipher(encryptionKey));
runApp(const NaKiFlutter());
}
class NaKiFlutter extends StatelessWidget {
const NaKiFlutter({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
routerConfig: nakiRouter,
theme: ThemeData(textTheme: GoogleFonts.robotoTextTheme()),
);
}
}