From 7651d5200767a339089dd4021bf77a86b6adcf80 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 11 Sep 2023 01:00:14 +0530 Subject: first commit --- lib/main.dart | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 lib/main.dart (limited to 'lib/main.dart') 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 createState() => _MyAppState(); +} + +class _MyAppState extends State { + final _storage = const FlutterSecureStorage(); + + String _authToken = ""; + String _refreshToken = ""; + String _version = ""; + + @override + void initState() { + super.initState(); + + _readAll(); + } + + Future _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: [ + 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: [ + 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 = ""; + }); + }, + ), + ], + ) + ], + ), + ) + ); + } + } +} -- cgit v1.2.3