Skip to content

Commit

Permalink
Refactor if-case patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
proninyaroslav committed Sep 12, 2024
1 parent 845d2bd commit 468a41d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/ui/model/app_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AppCubit extends Cubit<AppState> {
}

void setTheme(AppThemeType theme) {
if (state.locale case final locale?) {
if (state case AppState(:final locale?)) {
emit(AppState.changed(
theme: theme,
locale: locale,
Expand All @@ -62,7 +62,7 @@ class AppCubit extends Cubit<AppState> {
}

void setLocale(AppLocaleType locale) {
if (state.theme case final theme?) {
if (state case AppState(:final theme?)) {
emit(AppState.changed(
theme: theme,
locale: locale,
Expand Down
10 changes: 5 additions & 5 deletions lib/ui/settings/model/appearance_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AppearanceSettingsCubit extends Cubit<AppearanceState> {
}

Future<void> setTheme(AppThemeType theme) async {
if (state.info case final info?) {
if (state case AppearanceState(:final info?)) {
await _pref.setTheme(theme);
_appCubit.setTheme(theme);
emit(AppearanceState.themeChanged(
Expand All @@ -56,7 +56,7 @@ class AppearanceSettingsCubit extends Cubit<AppearanceState> {
}

Future<void> trackingNotify({required bool enable}) async {
if (state.info case final info?) {
if (state case AppearanceState(:final info?)) {
await _pref.setTrackingNotifications(enable);
emit(AppearanceState.trackingNotifyChanged(
info.copyWith(trackingNotify: enable),
Expand All @@ -65,7 +65,7 @@ class AppearanceSettingsCubit extends Cubit<AppearanceState> {
}

Future<void> setLocale(AppLocaleType locale) async {
if (state.info case final info?) {
if (state case AppearanceState(:final info?)) {
await _pref.setLocale(locale);
_appCubit.setLocale(locale);
emit(AppearanceState.localeChanged(
Expand All @@ -75,7 +75,7 @@ class AppearanceSettingsCubit extends Cubit<AppearanceState> {
}

Future<void> trackingErrorNotify({required bool enable}) async {
if (state.info case final info?) {
if (state case AppearanceState(:final info?)) {
await _pref.setTrackingErrorNotifications(enable);
emit(AppearanceState.trackingErrorNotifyChanged(
info.copyWith(trackingErrorNotify: enable),
Expand All @@ -84,7 +84,7 @@ class AppearanceSettingsCubit extends Cubit<AppearanceState> {
}

Future<void> trayIcon({required bool enable}) async {
if (state.info case final info?) {
if (state case AppearanceState(:final info?)) {
await _pref.setTrayIcon(enable);
await _systemTray.switchTrayIcon(enable: enable);
emit(AppearanceState.trayIconChanged(
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/settings/model/behavior_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BehaviorSettingsCubit extends Cubit<BehaviorState> {
}

Future<void> setTrackingLimit(TrackingFreqLimit limit) async {
if (state.info case final info?) {
if (state case BehaviorState(:final info?)) {
await _pref.setTrackingFrequencyLimit(limit);
emit(BehaviorState.trackingLimitChanged(
info.copyWith(trackingLimit: limit),
Expand All @@ -53,7 +53,7 @@ class BehaviorSettingsCubit extends Cubit<BehaviorState> {
}

Future<void> autoTracking({required bool enable}) async {
if (state.info case final info?) {
if (state case BehaviorState(:final info?)) {
await _pref.setAutoTracking(enable);
await _trackingScheduler.reenqueueAll();
emit(BehaviorState.autoTrackingChanged(
Expand All @@ -63,7 +63,7 @@ class BehaviorSettingsCubit extends Cubit<BehaviorState> {
}

Future<void> setAutoTrackingFreq(AutoTrackingFreq freq) async {
if (state.info case final info?) {
if (state case BehaviorState(:final info?)) {
await _pref.setAutoTrackingFreq(freq);
_trackingScheduler.reenqueueAll();
emit(BehaviorState.autoTrackingFreqChanged(
Expand All @@ -73,7 +73,7 @@ class BehaviorSettingsCubit extends Cubit<BehaviorState> {
}

Future<void> setTrackingHistorySize(int size) async {
if (state.info case final info?) {
if (state case BehaviorState(:final info?)) {
await _pref.setTrackingHistorySize(size);
emit(BehaviorState.trackingHistorySizeChanged(
info.copyWith(trackingHistorySize: size),
Expand Down

0 comments on commit 468a41d

Please sign in to comment.