main.dart formatting / commenting

This commit is contained in:
Drake Marino 2024-06-28 20:59:05 -05:00
parent 72e27525e7
commit b203a1aa6c

View File

@ -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<MainApp> {
@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<MainApp> {
}
}
@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,
);
}
}