FBLA24/fbla_ui/lib/main.dart
2024-06-23 14:36:18 -05:00

125 lines
3.8 KiB
Dart

import 'package:fbla_ui/home.dart';
import 'package:fbla_ui/shared/global_vars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final prefs = await SharedPreferences.getInstance();
bool? isDark = prefs.getBool('isDark');
themeMode = isDark != null && isDark
? ThemeMode.dark
: isDark != null && !isDark
? ThemeMode.light
: ThemeMode.system;
runApp(const MaterialApp(
title: 'Job Link',
home: MainApp(),
));
}
class MainApp extends StatefulWidget {
final int? initialPage;
const MainApp({super.key, this.initialPage});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
void _switchTheme() async {
final prefs = await SharedPreferences.getInstance();
if (MediaQuery.of(context).platformBrightness == Brightness.dark &&
themeMode == ThemeMode.system) {
setState(() {
themeMode = ThemeMode.light;
});
prefs.setBool('isDark', false);
} else if (MediaQuery.of(context).platformBrightness == Brightness.light &&
themeMode == ThemeMode.system) {
setState(() {
themeMode = ThemeMode.dark;
});
prefs.setBool('isDark', true);
} else if (themeMode == ThemeMode.light) {
setState(() {
themeMode = ThemeMode.dark;
});
prefs.setBool('isDark', true);
} else if (themeMode == ThemeMode.dark) {
setState(() {
themeMode = ThemeMode.light;
});
prefs.setBool('isDark', false);
}
}
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
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,
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(
// border: OutlineInputBorder(),
filled: true,
fillColor: Colors.grey.withOpacity(0.1),
labelStyle: 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,
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.blue.withOpacity(0.1),
labelStyle: const TextStyle(color: Colors.grey),
),
dropdownMenuTheme: const DropdownMenuThemeData(
inputDecorationTheme: InputDecorationTheme(
filled: true,
),
),
useMaterial3: true,
),
home: Home(themeCallback: _switchTheme, initialPage: widget.initialPage),
);
}
}