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 = ""; }); }, ), ], ) ], ), ) ); } } }