143 lines
4.7 KiB
Dart
143 lines
4.7 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,
|
|
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),
|
|
outlineBorder: BorderSide(color: Colors.grey.shade700),
|
|
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),
|
|
border: OutlineInputBorder(
|
|
borderSide: BorderSide(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),
|
|
);
|
|
}
|
|
}
|