Constant Dark Theme
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:witl/theme_manager.dart';
|
||||||
|
|
||||||
class Settings extends StatelessWidget {
|
class Settings extends StatelessWidget {
|
||||||
const Settings({super.key});
|
const Settings({super.key});
|
||||||
@@ -7,8 +8,14 @@ class Settings extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text("Settings Screen"),
|
title: const Text("Settings"),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
body: ListView(
|
||||||
|
children: [
|
||||||
|
|
||||||
|
],
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,8 +15,23 @@ class MyApp extends StatelessWidget {
|
|||||||
title: "Entry Point",
|
title: "Entry Point",
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
|
primaryColor: Colors.white,
|
||||||
|
brightness: Brightness.light,
|
||||||
|
dividerColor: Colors.white54,
|
||||||
|
scaffoldBackgroundColor: Colors.white,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
darkTheme: ThemeData(
|
||||||
|
primarySwatch: Colors.blue,
|
||||||
|
primaryColor: Colors.black,
|
||||||
|
brightness: Brightness.dark,
|
||||||
|
dividerColor: Colors.black12,
|
||||||
|
scaffoldBackgroundColor: Color(0xFF131313),
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
themeMode: ThemeMode.system,
|
||||||
|
|
||||||
// Navigashun with Routes
|
// Navigashun with Routes
|
||||||
// Base "Home" Route
|
// Base "Home" Route
|
||||||
initialRoute: '/',
|
initialRoute: '/',
|
||||||
|
|||||||
27
lib/storage_manager.dart
Normal file
27
lib/storage_manager.dart
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class StorageManager {
|
||||||
|
static void saveData(String key, dynamic value) async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
if (value is int) {
|
||||||
|
prefs.setInt(key, value);
|
||||||
|
} else if (value is String) {
|
||||||
|
prefs.setString(key, value);
|
||||||
|
} else if (value is bool) {
|
||||||
|
prefs.setBool(key, value);
|
||||||
|
} else {
|
||||||
|
throw("Invalid Type (Shared Preference Error)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<dynamic> readData(String key) async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
dynamic obj = prefs.get(key);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<bool> deleteData(String key) async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
return prefs.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
lib/theme_manager.dart
Normal file
45
lib/theme_manager.dart
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:witl/storage_manager.dart';
|
||||||
|
|
||||||
|
class ThemeNotifier with ChangeNotifier {
|
||||||
|
final darkTheme = ThemeData(
|
||||||
|
primaryColor: Colors.black,
|
||||||
|
brightness: Brightness.dark,
|
||||||
|
dividerColor: Colors.black12, colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.grey).copyWith(background: const Color(0xFF212121)),
|
||||||
|
);
|
||||||
|
|
||||||
|
final lightTheme = ThemeData(
|
||||||
|
primaryColor: Colors.white,
|
||||||
|
brightness: Brightness.light,
|
||||||
|
dividerColor: Colors.white54, colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.grey).copyWith(background: const Color(0xFFE5E5E5)),
|
||||||
|
);
|
||||||
|
|
||||||
|
late ThemeData _themeData;
|
||||||
|
ThemeData getTheme() => _themeData;
|
||||||
|
|
||||||
|
ThemeNotifier() {
|
||||||
|
StorageManager.readData('themeMode').then((value) {
|
||||||
|
'value read from storage: ' + value.toString();
|
||||||
|
var themeMode = value ?? 'light';
|
||||||
|
if (themeMode == 'light') {
|
||||||
|
_themeData = lightTheme;
|
||||||
|
} else {
|
||||||
|
'setting dark theme';
|
||||||
|
_themeData = darkTheme;
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDarkMode() async {
|
||||||
|
_themeData = darkTheme;
|
||||||
|
StorageManager.saveData('themeMode', 'dark');
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLightMode() async {
|
||||||
|
_themeData = lightTheme;
|
||||||
|
StorageManager.saveData('themeMode', 'light');
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user