Skip to content

Commit

Permalink
refactor: Rename enum and update references
Browse files Browse the repository at this point in the history
  • Loading branch information
yorifuji committed Apr 27, 2024
1 parent 37ead3f commit ea35bdc
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 57 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ Android および iOS のみ対応、`--dart-define=FLAVOR=...` で切り替え
- GitHub Pages
- Nightly build

# 素材

- https://loosedrawing.com/

# Related repository

- [yorifuji/buzz_recipe_importer](https://github.com/yorifuji/buzz_recipe_importer)
Expand Down
3 changes: 2 additions & 1 deletion lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class App extends ConsumerWidget {
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: LocalePreference.supportedLocaleList(),
home: ref.watch(boolPreferenceProvider(BoolKey.shouldShowWalkthrough))
home: ref.watch(
boolPreferenceProvider(BoolPreferenceKey.shouldShowWalkthrough))
? const WalkthroughPage()
: const NavigationPage(),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions lib/repository/preference_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'preference_repository.g.dart';

enum BoolKey {
enum BoolPreferenceKey {
useInternalPlayer('use_internal_player', true),
shouldShowWalkthrough('should_show_walkthrough', true),
;

// ignore: avoid_positional_boolean_parameters
const BoolKey(this.key, this.defaultValue);
const BoolPreferenceKey(this.key, this.defaultValue);
final String key;
final bool defaultValue;
}

enum IntKey {
enum IntPreferenceKey {
themeMode('theme_mode', 0),
locale('locale', 0),
;

const IntKey(this.key, this.defaultValue);
const IntPreferenceKey(this.key, this.defaultValue);
final String key;
final int defaultValue;
}

enum StringKey {
enum StringPreferenceKey {
appColor('app_color', ''),
;

const StringKey(this.key, this.defaultValue);
const StringPreferenceKey(this.key, this.defaultValue);
final String key;
final String defaultValue;
}

@riverpod
class BoolPreference extends _$BoolPreference {
@override
bool build(BoolKey keyValue) =>
bool build(BoolPreferenceKey keyValue) =>
ref.watch(sharedPreferencesProvider).getBool(keyValue.key) ??
keyValue.defaultValue;

Expand All @@ -51,7 +51,7 @@ class BoolPreference extends _$BoolPreference {
@riverpod
class IntPreference extends _$IntPreference {
@override
int build(IntKey keyValue) =>
int build(IntPreferenceKey keyValue) =>
ref.watch(sharedPreferencesProvider).getInt(keyValue.key) ??
keyValue.defaultValue;

Expand All @@ -64,7 +64,7 @@ class IntPreference extends _$IntPreference {
@riverpod
class StringPreference extends _$StringPreference {
@override
String build(StringKey keyValue) =>
String build(StringPreferenceKey keyValue) =>
ref.watch(sharedPreferencesProvider).getString(keyValue.key) ??
keyValue.defaultValue;

Expand All @@ -78,14 +78,14 @@ class FakeTruePreference extends _$BoolPreference
with Mock
implements BoolPreference {
@override
bool build(BoolKey keyValue) => true;
bool build(BoolPreferenceKey keyValue) => true;
}

class FakeFalsePreference extends _$BoolPreference
with Mock
implements BoolPreference {
@override
bool build(BoolKey keyValue) => false;
bool build(BoolPreferenceKey keyValue) => false;
}

class FakeIntPreference extends _$IntPreference
Expand All @@ -96,5 +96,5 @@ class FakeIntPreference extends _$IntPreference
// ignore: avoid_public_notifier_properties
final int value;
@override
int build(IntKey keyValue) => value;
int build(IntPreferenceKey keyValue) => value;
}
49 changes: 25 additions & 24 deletions lib/repository/preference_repository.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/service/video_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:buzz_recipe_viewer/model/sort_index.dart';
import 'package:buzz_recipe_viewer/provider/flavor_provider.dart';
import 'package:buzz_recipe_viewer/repository/video_repository.dart';
import 'package:buzz_recipe_viewer/repository/video_repository_mock.dart';
import 'package:buzz_recipe_viewer/store/search_state_store.dart';
import 'package:buzz_recipe_viewer/store/video/search_state_store.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'video_service.g.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/service/video_service.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/store/app_color_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ part 'app_color_notifier.g.dart';
class AppColorNotifer extends _$AppColorNotifer {
@override
AppColor build() {
final appColor = ref.watch(stringPreferenceProvider(StringKey.appColor));
final appColor =
ref.watch(stringPreferenceProvider(StringPreferenceKey.appColor));
return AppColor.fromName(appColor);
}

Future<void> update(AppColor appColor) async {
await ref
.read(stringPreferenceProvider(StringKey.appColor).notifier)
.read(stringPreferenceProvider(StringPreferenceKey.appColor).notifier)
.update(appColor.name);
ref.invalidateSelf();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/store/app_color_notifier.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/store/locale_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ part 'locale_notifier.g.dart';
class LocaleNotifer extends _$LocaleNotifer {
@override
LocalePreference build() {
final index = ref.watch(intPreferenceProvider(IntKey.locale));
final index = ref.watch(intPreferenceProvider(IntPreferenceKey.locale));
final localePreference = LocalePreference.fromIndex(index);
_applyLocaleSettings(localePreference);
return localePreference;
}

Future<void> update(LocalePreference localePreference) async {
await ref
.read(intPreferenceProvider(IntKey.locale).notifier)
.read(intPreferenceProvider(IntPreferenceKey.locale).notifier)
.update(localePreference.index);
ref.invalidateSelf();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/store/locale_notifier.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/store/theme_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ part 'theme_notifier.g.dart';
class ThemeNotifer extends _$ThemeNotifer {
@override
ThemePreference build() {
final index = ref.watch(intPreferenceProvider(IntKey.themeMode));
final index = ref.watch(intPreferenceProvider(IntPreferenceKey.themeMode));
return ThemePreference.fromIndex(index);
}

Future<void> update(ThemePreference themeModePreference) async {
await ref
.read(intPreferenceProvider(IntKey.themeMode).notifier)
.read(intPreferenceProvider(IntPreferenceKey.themeMode).notifier)
.update(themeModePreference.index);
ref.invalidateSelf();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/store/theme_notifier.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ea35bdc

Please sign in to comment.