From b203a1aa6c5bc7e36f8cffb321e0ddf60e8d1ee2 Mon Sep 17 00:00:00 2001 From: drake Date: Fri, 28 Jun 2024 20:59:05 -0500 Subject: [PATCH] main.dart formatting / commenting --- fbla_ui/lib/main.dart | 155 +++++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 71 deletions(-) diff --git a/fbla_ui/lib/main.dart b/fbla_ui/lib/main.dart index 945a69c..fddd41d 100644 --- a/fbla_ui/lib/main.dart +++ b/fbla_ui/lib/main.dart @@ -21,6 +21,7 @@ void main() async { )); } +/// Main app page loader and theme manager class MainApp extends StatefulWidget { final int? initialPage; @@ -31,6 +32,24 @@ class MainApp extends StatefulWidget { } class _MainAppState extends State { + @override + Widget build(BuildContext context) { + // prevent landscape mode (it looks bad) + SystemChrome.setPreferredOrientations([ + DeviceOrientation.portraitUp, + DeviceOrientation.portraitDown, + ]); + + return MaterialApp( + title: 'Job Link', + themeMode: themeMode, + darkTheme: _darkThemeData(), + theme: _lightThemeData(), + home: Home(themeCallback: _switchTheme, initialPage: widget.initialPage), + ); + } + + /// Switch the theme mode based on the currently selected theme and the system prefs void _switchTheme() async { final prefs = await SharedPreferences.getInstance(); if (MediaQuery.of(context).platformBrightness == Brightness.dark && @@ -58,82 +77,76 @@ class _MainAppState extends State { } } - @override - Widget build(BuildContext context) { - SystemChrome.setPreferredOrientations([ - DeviceOrientation.portraitUp, - DeviceOrientation.portraitDown, - ]); + /// Static theme for dark mode + ThemeData _darkThemeData() { + return ThemeData( + scaffoldBackgroundColor: const Color(0xFF121212), + colorScheme: ColorScheme.dark( + brightness: Brightness.dark, + primary: Colors.blue.shade700, + onPrimary: Colors.white, + secondary: Colors.blue.shade900, + onSecondary: Colors.white, + surface: const Color.fromARGB(255, 31, 31, 31), + surfaceContainer: const Color.fromARGB(255, 46, 46, 46), + tertiary: Colors.green.shade900, + ), + iconTheme: const IconThemeData(color: Colors.white), + useMaterial3: true, + inputDecorationTheme: InputDecorationTheme( + filled: true, + fillColor: Colors.grey.withOpacity(0.1), + labelStyle: const TextStyle(color: Colors.grey), + floatingLabelStyle: WidgetStateTextStyle.resolveWith((states) { + if (states.contains(WidgetState.focused) && + !states.contains(WidgetState.hovered)) { + return TextStyle(color: Colors.blue.shade700); + } + return const TextStyle(color: Colors.grey); + }), + ), + dropdownMenuTheme: const DropdownMenuThemeData( + inputDecorationTheme: InputDecorationTheme( + filled: true, + ), + ), + ); + } - return MaterialApp( - title: 'Job Link', - themeMode: themeMode, - darkTheme: ThemeData( - scaffoldBackgroundColor: const Color(0xFF121212), - colorScheme: ColorScheme.dark( - brightness: Brightness.dark, - primary: Colors.blue.shade700, - onPrimary: Colors.white, - secondary: Colors.blue.shade900, - onSecondary: Colors.white, - surface: const Color.fromARGB(255, 31, 31, 31), - surfaceContainer: const Color.fromARGB(255, 46, 46, 46), - tertiary: Colors.green.shade900, - ), - iconTheme: const IconThemeData(color: Colors.white), - useMaterial3: true, + /// Static theme for light mode + ThemeData _lightThemeData() { + return ThemeData( + scaffoldBackgroundColor: Colors.grey.shade300, + colorScheme: ColorScheme.light( + brightness: Brightness.light, + primary: Colors.blue.shade700, + onPrimary: Colors.white, + secondary: Colors.blue.shade300, + onSecondary: Colors.black, + surface: Colors.grey.shade100, + surfaceContainer: Colors.grey.shade200, + tertiary: Colors.green, + ), + iconTheme: const IconThemeData(color: Colors.black), + inputDecorationTheme: InputDecorationTheme( + // border: OutlineInputBorder(), + filled: true, + fillColor: Colors.grey.withOpacity(0.25), + labelStyle: TextStyle(color: Colors.grey.shade700), + floatingLabelStyle: WidgetStateTextStyle.resolveWith((states) { + if (states.contains(WidgetState.focused) && + !states.contains(WidgetState.hovered)) { + return TextStyle(color: Colors.blue.shade700); + } + return TextStyle(color: Colors.grey.shade700); + }), + ), + dropdownMenuTheme: const DropdownMenuThemeData( inputDecorationTheme: InputDecorationTheme( filled: true, - fillColor: Colors.grey.withOpacity(0.1), - labelStyle: const TextStyle(color: Colors.grey), - floatingLabelStyle: WidgetStateTextStyle.resolveWith((states) { - if (states.contains(WidgetState.focused) && - !states.contains(WidgetState.hovered)) { - return TextStyle(color: Colors.blue.shade700); - } - return const TextStyle(color: Colors.grey); - }), - ), - dropdownMenuTheme: const DropdownMenuThemeData( - inputDecorationTheme: InputDecorationTheme( - filled: true, - ), ), ), - theme: ThemeData( - scaffoldBackgroundColor: Colors.grey.shade300, - colorScheme: ColorScheme.light( - brightness: Brightness.light, - primary: Colors.blue.shade700, - onPrimary: Colors.white, - secondary: Colors.blue.shade300, - onSecondary: Colors.black, - surface: Colors.grey.shade100, - surfaceContainer: Colors.grey.shade200, - tertiary: Colors.green, - ), - iconTheme: const IconThemeData(color: Colors.black), - inputDecorationTheme: InputDecorationTheme( - // border: OutlineInputBorder(), - filled: true, - fillColor: Colors.grey.withOpacity(0.25), - labelStyle: TextStyle(color: Colors.grey.shade700), - floatingLabelStyle: WidgetStateTextStyle.resolveWith((states) { - if (states.contains(WidgetState.focused) && - !states.contains(WidgetState.hovered)) { - return TextStyle(color: Colors.blue.shade700); - } - return TextStyle(color: Colors.grey.shade700); - }), - ), - dropdownMenuTheme: const DropdownMenuThemeData( - inputDecorationTheme: InputDecorationTheme( - filled: true, - ), - ), - useMaterial3: true, - ), - home: Home(themeCallback: _switchTheme, initialPage: widget.initialPage), + useMaterial3: true, ); } }