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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
import "package:flutter/material.dart";
import "package:flutter_secure_storage/flutter_secure_storage.dart";
//import "package:window_manager/window_manager.dart";
import "package:openbills/screens/login.dart";
import "package:openbills/widgets/snackbar.dart";
import "package:openbills/models/instance.dart";
void main() async {
//WidgetsFlutterBinding.ensureInitialized();
//await windowManager.ensureInitialized();
//WindowOptions windowOptions = const WindowOptions(
// minimumSize: Size(400, 600),
// center: true,
// backgroundColor: Colors.transparent,
// skipTaskbar: false,
// titleBarStyle: TitleBarStyle.normal,
//);
//windowManager.waitUntilReadyToShow(windowOptions, () async {
// await windowManager.show();
// await windowManager.focus();
//});
runApp(MaterialApp(
title: "OpenBills",
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
//themeMode: ThemeMode.system,
themeMode: ThemeMode.dark,
//home: const HomeScreen(),
home: const MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _storage = const FlutterSecureStorage();
String _authToken = "";
String _refreshToken = "";
String _version = "";
@override
void initState() {
super.initState();
_readAll();
}
Future<void> _readAll() async {
final authToken = await _storage.read(key: "auth_token", aOptions: const AndroidOptions(
encryptedSharedPreferences: true,
));
final refreshToken = await _storage.read(key: "refresh_token", aOptions: const AndroidOptions(
encryptedSharedPreferences: true,
));
final Instance instance = await getInstance("https://openbills.vidhukant.com");
setState(() {
if (authToken != null) {
_authToken = authToken.toString();
}
if (refreshToken != null) {
_refreshToken = refreshToken.toString();
}
_version = instance.version;
});
}
@override
Widget build(BuildContext context) {
if (_authToken == "") {
return const LoginScreen();
} else {
return Scaffold(
appBar: AppBar(
title: const Text("OpenBills Home Screen"),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
child: Column(
children: <Widget>[
Text(
"You are logged into OpenBills $_version!",
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 50,
),
Text(
"Auth Bearer Token: $_authToken",
),
const SizedBox(
height: 25,
),
Text(
"Refresh Token: $_refreshToken",
),
const SizedBox(
height: 50,
),
const Text(
"Well yeah this doesn't do much but yay this is pretty cool",
),
const SizedBox(
height: 50,
),
Row (
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
TextButton(
child: const Text("Log Out"),
onPressed: () async {
await _storage.delete(key: "auth_token");
await _storage.delete(key: "refresh_token");
if (context.mounted) {
MySnackBar.show(context, "You have been logged out.");
}
setState(() {
_authToken = "";
});
},
),
],
)
],
),
)
);
}
}
}
|