import 'package:fbla_ui/home.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:shared_preferences/shared_preferences.dart'; ThemeMode themeMode = ThemeMode.system; 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 bool? isDark; const MainApp({super.key, this.isDark}); @override State createState() => _MainAppState(); } class _MainAppState extends State { 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, // themeMode: ThemeMode.light, darkTheme: ThemeData( colorScheme: ColorScheme.dark( brightness: Brightness.dark, primary: Colors.blue, onPrimary: Colors.white, secondary: Colors.blue.shade900, background: const Color.fromARGB(255, 31, 31, 31), tertiary: Colors.green.shade900, ), iconTheme: const IconThemeData(color: Colors.white), inputDecorationTheme: const InputDecorationTheme(), useMaterial3: true, ), theme: ThemeData( colorScheme: ColorScheme.light( brightness: Brightness.light, primary: Colors.blue, onPrimary: Colors.white, secondary: Colors.blue.shade200, background: Colors.white, tertiary: Colors.green, ), iconTheme: const IconThemeData(color: Colors.black), inputDecorationTheme: const InputDecorationTheme(border: UnderlineInputBorder()), useMaterial3: true, ), home: Home(themeCallback: _switchTheme), ); } }