This repository has been archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
home_route.dart
86 lines (75 loc) · 2.43 KB
/
home_route.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
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
82
83
84
85
86
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get_it/get_it.dart';
import 'package:paperless_app/routes/documents_route.dart';
import 'package:paperless_app/routes/login_route.dart';
import 'package:paperless_app/routes/server_details_route.dart';
import '../api.dart';
class HomeRoute extends StatefulWidget {
@override
State<StatefulWidget> createState() => _HomeRouteState();
}
class _HomeRouteState extends State<HomeRoute> {
GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: Center(
child: SizedBox(
height: 155.0,
child: SvgPicture.asset(
"assets/logo.svg",
color: Colors.green,
fit: BoxFit.contain,
),
),
));
}
void loadData() async {
var url;
try {
url = await GetIt.I<FlutterSecureStorage>().read(key: "server_url");
} catch (e, s) {
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(SnackBar(
content: Text("Unable to access secure storage: $e ($s))"),
duration: Duration(seconds: 15),
));
}
if (url == null) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => ServerDetailsRoute()),
);
return;
}
var username = await GetIt.I<FlutterSecureStorage>().read(key: "username");
var password = await GetIt.I<FlutterSecureStorage>().read(key: "password");
var trustedCertificateSha512 = await GetIt.I<FlutterSecureStorage>()
.read(key: "trustedCertificateSha512");
var apiFlavour =
await GetIt.I<FlutterSecureStorage>().read(key: "api_flavour");
if (username == null || password == null) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LoginRoute()),
);
return;
}
if (apiFlavour == null) {
apiFlavour = "paperless";
}
API.trustedCertificateSha512 = trustedCertificateSha512;
API(url, username: username, password: password, apiFlavour: apiFlavour);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => DocumentsRoute()),
);
}
@override
void initState() {
loadData();
super.initState();
}
}