Complete refactoring SFM App Source Code
This commit is contained in:
5
lib/product/theme/app_theme.dart
Normal file
5
lib/product/theme/app_theme.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract class AppTheme {
|
||||
ThemeData? theme;
|
||||
}
|
||||
53
lib/product/theme/app_theme_dark.dart
Normal file
53
lib/product/theme/app_theme_dark.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sfm_app/product/theme/app_theme.dart';
|
||||
|
||||
class AppThemeDark extends AppTheme {
|
||||
static AppThemeDark? _instance;
|
||||
static AppThemeDark get instance {
|
||||
_instance ??= AppThemeDark._init();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
AppThemeDark._init();
|
||||
|
||||
@override
|
||||
ThemeData get theme => FlexThemeData.dark(
|
||||
useMaterial3: true,
|
||||
scheme: FlexScheme.flutterDash,
|
||||
subThemesData: const FlexSubThemesData(
|
||||
inputDecoratorRadius: 30,
|
||||
interactionEffects: true,
|
||||
tintedDisabledControls: true,
|
||||
blendOnColors: true,
|
||||
useM2StyleDividerInM3: true,
|
||||
inputDecoratorBorderType: FlexInputBorderType.outline,
|
||||
tooltipRadius: 20,
|
||||
tooltipWaitDuration: Duration(milliseconds: 500),
|
||||
tooltipShowDuration: Duration(milliseconds: 500),
|
||||
navigationRailUseIndicator: true,
|
||||
navigationRailLabelType: NavigationRailLabelType.all,
|
||||
),
|
||||
visualDensity: FlexColorScheme.comfortablePlatformDensity,
|
||||
);
|
||||
|
||||
// ThemeData.dark().copyWith(
|
||||
// useMaterial3: true,
|
||||
// colorScheme: _buildColorScheme,
|
||||
// );
|
||||
|
||||
// ColorScheme get _buildColorScheme => FlexColorScheme.dark().toScheme;
|
||||
// ColorScheme(
|
||||
// brightness: Brightness.dark,
|
||||
// primary: Colors.blue.shade900,
|
||||
// onPrimary: Colors.blue,
|
||||
// secondary: Colors.white,
|
||||
// onSecondary: Colors.white70,
|
||||
// error: Colors.red,
|
||||
// onError: Colors.orange,
|
||||
// background: Colors.black,
|
||||
// onBackground: Colors.white70,
|
||||
// surface: Colors.grey,
|
||||
// onSurface: Colors.white,
|
||||
// );
|
||||
}
|
||||
54
lib/product/theme/app_theme_light.dart
Normal file
54
lib/product/theme/app_theme_light.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sfm_app/product/theme/app_theme.dart';
|
||||
|
||||
class AppThemeLight extends AppTheme {
|
||||
static AppThemeLight? _instance;
|
||||
static AppThemeLight get instance {
|
||||
_instance ??= AppThemeLight._init();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
AppThemeLight._init();
|
||||
|
||||
@override
|
||||
ThemeData get theme => FlexThemeData.light(
|
||||
useMaterial3: true,
|
||||
scheme: FlexScheme.flutterDash,
|
||||
bottomAppBarElevation: 20.0,
|
||||
subThemesData: const FlexSubThemesData(
|
||||
inputDecoratorRadius: 30,
|
||||
interactionEffects: true,
|
||||
tintedDisabledControls: true,
|
||||
useM2StyleDividerInM3: true,
|
||||
inputDecoratorBorderType: FlexInputBorderType.outline,
|
||||
tooltipRadius: 20,
|
||||
tooltipWaitDuration: Duration(milliseconds: 1600),
|
||||
tooltipShowDuration: Duration(milliseconds: 1500),
|
||||
navigationRailUseIndicator: true,
|
||||
navigationRailLabelType: NavigationRailLabelType.all,
|
||||
),
|
||||
visualDensity: FlexColorScheme.comfortablePlatformDensity,
|
||||
);
|
||||
// ThemeData.light().copyWith(
|
||||
// useMaterial3: true,
|
||||
// colorScheme: _buildColorScheme,
|
||||
// );
|
||||
|
||||
// ColorScheme get _buildColorScheme => FlexColorScheme.light(
|
||||
|
||||
// ).toScheme;
|
||||
// const ColorScheme(
|
||||
// brightness: Brightness.light,
|
||||
// primary: Colors.black,
|
||||
// onPrimary: Colors.white,
|
||||
// secondary: Colors.black,
|
||||
// onSecondary: Colors.black45,
|
||||
// error: Colors.red,
|
||||
// onError: Colors.orange,
|
||||
// background: Colors.white,
|
||||
// onBackground: Colors.red,
|
||||
// surface: Colors.white,
|
||||
// onSurface: Colors.black,
|
||||
// );
|
||||
}
|
||||
23
lib/product/theme/provider/app_provider.dart
Normal file
23
lib/product/theme/provider/app_provider.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:provider/single_child_widget.dart';
|
||||
|
||||
import '../theme_notifier.dart';
|
||||
|
||||
class ApplicationProvider {
|
||||
static ApplicationProvider? _instance;
|
||||
static ApplicationProvider get instance {
|
||||
_instance ??= ApplicationProvider._init();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
ApplicationProvider._init();
|
||||
|
||||
List<SingleChildWidget> singleItems = [];
|
||||
List<SingleChildWidget> dependItems = [
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => ThemeNotifier(),
|
||||
),
|
||||
// Provider.value(value: NavigationService.instance)
|
||||
];
|
||||
List<SingleChildWidget> uiChangesItems = [];
|
||||
}
|
||||
104
lib/product/theme/theme_notifier.dart
Normal file
104
lib/product/theme/theme_notifier.dart
Normal file
@@ -0,0 +1,104 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'app_theme_dark.dart';
|
||||
import 'app_theme_light.dart';
|
||||
|
||||
import '../constant/enums/app_theme_enums.dart';
|
||||
|
||||
class ThemeNotifier extends ChangeNotifier {
|
||||
// ThemeData _currentTheme = AppThemeLight.instance.theme;
|
||||
// // ThemeData get currentTheme => LocaleManager.instance.getStringValue(PreferencesKeys.THEME) ==
|
||||
// // AppThemes.LIGHT.name
|
||||
// // ? AppThemeLight.instance.theme
|
||||
// // : AppThemeDark.instance.theme;
|
||||
// ThemeData get currentTheme {
|
||||
// log("ThemeKey: ${LocaleManager.instance.getStringValue(PreferencesKeys.THEME)}");
|
||||
// if (LocaleManager.instance.getStringValue(PreferencesKeys.THEME) ==
|
||||
// AppThemes.LIGHT.name) {
|
||||
// log("light");
|
||||
// } else {
|
||||
// log("dark");
|
||||
// }
|
||||
// return LocaleManager.instance.getStringValue(PreferencesKeys.THEME) ==
|
||||
// AppThemes.LIGHT.name
|
||||
// ? AppThemeLight.instance.theme
|
||||
// : AppThemeDark.instance.theme;
|
||||
// }
|
||||
|
||||
// ThemeData _currentTheme = AppThemeLight.instance.theme; // Mặc định là light
|
||||
|
||||
// ThemeNotifier() {
|
||||
// loadThemeFromPreferences();
|
||||
// }
|
||||
|
||||
// Future<void> loadThemeFromPreferences() async {
|
||||
// String themeKey =
|
||||
// LocaleManager.instance.getStringValue(PreferencesKeys.THEME);
|
||||
// log("ThemeNotifierKey:$themeKey ");
|
||||
// if (themeKey == AppThemes.LIGHT.name) {
|
||||
// _currentTheme = AppThemeLight.instance.theme;
|
||||
// } else {
|
||||
// _currentTheme = AppThemeDark.instance.theme;
|
||||
// }
|
||||
// notifyListeners(); // Thông báo cho các widget lắng nghe
|
||||
// }
|
||||
|
||||
// ThemeData get currentTheme => _currentTheme;
|
||||
|
||||
// AppThemes _currenThemeEnum = AppThemes.LIGHT;
|
||||
// AppThemes get currenThemeEnum =>
|
||||
// LocaleManager.instance.getStringValue(PreferencesKeys.THEME) ==
|
||||
// AppThemes.LIGHT.name
|
||||
// ? AppThemes.LIGHT
|
||||
// : AppThemes.DARK;
|
||||
// // AppThemes get currenThemeEnum => _currenThemeEnum;
|
||||
|
||||
// void changeValue(AppThemes theme) {
|
||||
// if (theme == AppThemes.LIGHT) {
|
||||
// _currentTheme = ThemeData.dark();
|
||||
// } else {
|
||||
// _currentTheme = ThemeData.light();
|
||||
// }
|
||||
// notifyListeners();
|
||||
// }
|
||||
|
||||
// void changeTheme() {
|
||||
// if (_currenThemeEnum == AppThemes.LIGHT) {
|
||||
// _currentTheme = AppThemeDark.instance.theme;
|
||||
// _currenThemeEnum = AppThemes.DARK;
|
||||
// LocaleManager.instance
|
||||
// .setString(PreferencesKeys.THEME, AppThemes.DARK.name);
|
||||
// } else {
|
||||
// _currentTheme = AppThemeLight.instance.theme;
|
||||
// _currenThemeEnum = AppThemes.LIGHT;
|
||||
// LocaleManager.instance
|
||||
// .setString(PreferencesKeys.THEME, AppThemes.LIGHT.name);
|
||||
// }
|
||||
// notifyListeners();
|
||||
// }
|
||||
|
||||
ThemeData _currentTheme = AppThemeLight.instance.theme;
|
||||
ThemeData get currentTheme => _currentTheme;
|
||||
|
||||
AppThemes _currenThemeEnum = AppThemes.LIGHT;
|
||||
AppThemes get currenThemeEnum => _currenThemeEnum;
|
||||
|
||||
void changeValue(AppThemes theme) {
|
||||
if (theme == AppThemes.LIGHT) {
|
||||
_currentTheme = AppThemeLight.instance.theme;
|
||||
} else {
|
||||
_currentTheme = AppThemeDark.instance.theme;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void changeTheme() {
|
||||
if (_currenThemeEnum == AppThemes.LIGHT) {
|
||||
_currentTheme = AppThemeDark.instance.theme;
|
||||
_currenThemeEnum = AppThemes.DARK;
|
||||
} else {
|
||||
_currentTheme = AppThemeLight.instance.theme;
|
||||
_currenThemeEnum = AppThemes.LIGHT;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user