Dark mode persistence added in the app

haroon_dev
Haroon Amjad 20 hours ago
parent f46b3f745f
commit 040ff6a80d

@ -224,7 +224,7 @@ class AppDependencies {
authenticationRepo: getIt(), cacheService: getIt(), navigationService: getIt(), dialogService: getIt(), appState: getIt(), errorHandlerService: getIt(), localAuthService: getIt()),
);
getIt.registerLazySingleton<ProfileSettingsViewModel>(() => ProfileSettingsViewModel());
getIt.registerLazySingleton<ProfileSettingsViewModel>(() => ProfileSettingsViewModel(cacheService: getIt<CacheService>()));
getIt.registerLazySingleton<DateRangeSelectorRangeViewModel>(() => DateRangeSelectorRangeViewModel());

@ -1,14 +1,32 @@
import 'package:flutter/foundation.dart';
import 'package:hmg_patient_app_new/services/cache_service.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
class ProfileSettingsViewModel extends ChangeNotifier {
static const String _darkModeKey = 'is_dark_mode';
final CacheService _cacheService;
bool _isDarkMode = false;
bool get isDarkMode => _isDarkMode;
ProfileSettingsViewModel({required CacheService cacheService})
: _cacheService = cacheService;
/// Call once at app startup (before the first frame) to restore the
/// persisted dark-mode preference.
void loadDarkMode() {
final saved = _cacheService.getBool(key: _darkModeKey);
_isDarkMode = saved ?? false;
AppColors.isDarkMode = _isDarkMode;
// No notifyListeners() here we are called before build.
}
void toggleDarkMode(bool value) {
_isDarkMode = value;
AppColors.isDarkMode = value;
_cacheService.saveBool(key: _darkModeKey, value: value);
notifyListeners();
}

@ -111,6 +111,9 @@ Future<void> callInitializations() async {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
HttpOverrides.global = MyHttpOverrides();
await callAppStateInitializations();
// Restore persisted dark-mode preference before the first frame.
getIt.get<ProfileSettingsViewModel>().loadDarkMode();
}
void main() async {

@ -13,8 +13,8 @@ class LandingPageData {
title: LocaleKeys.emergency,
subtitle: LocaleKeys.services2,
backgroundColor: AppColors.primaryRedColor,
iconColor: AppColors.whiteColor,
textColor: AppColors.whiteColor,
iconColor: Colors.white,
textColor: Colors.white,
isBold: true,
),
ServiceCardData(

@ -296,9 +296,9 @@ class _LandingPageState extends State<LandingPage> {
context.navigateWithName(AppRoutes.userInfoSelection);
},
padding: EdgeInsetsGeometry.zero,
backgroundColor: Color(0xFF2B353E),
borderColor: Color(0xFF2B353E),
textColor: AppColors.whiteColor,
backgroundColor: AppColors.primaryRedColor,
borderColor: AppColors.primaryRedColor,
textColor: Colors.white,
fontSize: 14.f,
fontWeight: FontWeight.w600,
borderRadius: 12.r,

@ -40,7 +40,7 @@ class WelcomeWidget extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: [
Flexible(child: name.toText16(weight: FontWeight.w500, textOverflow: TextOverflow.ellipsis, maxlines: 1, height: 1)),
const Icon(Icons.keyboard_arrow_down, size: 20, color: Colors.black),
Icon(Icons.keyboard_arrow_down, size: 20, color: AppColors.greyTextColor),
],
),
],

@ -1,5 +1,6 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
class HealthChart extends StatelessWidget {
final List<FlSpot> spots;

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
class DatePickerWidget extends StatelessWidget {
final String labelText;

@ -67,7 +67,7 @@ class _PhoneNumberInputState extends State<PhoneNumberInput> {
)
.toList(),
onChanged: _onCountryCodeChanged,
icon: const Icon(
icon: Icon(
Icons.keyboard_arrow_down_rounded,
color: AppColors.mainPurple,
),

Loading…
Cancel
Save