diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-09-11 01:00:14 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-09-11 01:00:14 +0530 |
commit | 7651d5200767a339089dd4021bf77a86b6adcf80 (patch) | |
tree | 3fef13a7f0140b22716bfbc9a7c6e842782b853c /lib/main.dart |
first commitv0.0.1
Diffstat (limited to 'lib/main.dart')
-rw-r--r-- | lib/main.dart | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/lib/main.dart b/lib/main.dart new file mode 100644 index 0000000..09d16d7 --- /dev/null +++ b/lib/main.dart @@ -0,0 +1,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 = ""; + }); + }, + ), + ], + ) + ], + ), + ) + ); + } + } +} |