Skip to content

Commit

Permalink
feat: 4513 - user preferences pages simple refactoring (#4620)
Browse files Browse the repository at this point in the history
New files:
* `user_preferences_advanced_settings.dart`: used to be `_AdvancedSettings` in `user_preferences_settings.dart`
* `user_preferences_camera_sound.dart`: used to be `_CameraPlayScanSoundSetting` in `user_preferences_settings.dart`
* `user_preferences_choose_accent_color.dart`: used to be `_ChooseAccentColor` in `user_preferences_settings.dart`
* `user_preferences_choose_app_theme.dart`: used to be more or less `_ChooseAppTheme` in `user_preferences_settings.dart`
* `user_preferences_choose_text_color_contrast.dart`: used to be `_ChooseTextColorContrast` in `user_preferences_settings.dart`
* `user_preferences_country_selector.dart`: used to be coded in `user_preferences_settings.dart`
* `user_preferences_crash_reporting.dart`: used to be `_CrashReportingSetting` in `user_preferences_settings.dart`
* `user_preferences_haptic_feedback.dart`: used to be `_HapticFeedbackSetting` in `user_preferences_settings.dart`
* `user_preferences_image_source.dart`: used to be coded in `user_preferences_settings.dart`
* `user_preferences_language_selector.dart`: used to be coded in `user_preferences_settings.dart`
* `user_preferences_rate_us.dart`: used to be `_RateUs` in `user_preferences_settings.dart`
* `user_preferences_send_anonymous.dart`: used to be `_SendAnonymousDataSetting` in `user_preferences_settings.dart`
* `user_preferences_share_with_friends.dart`: used to be `_ShareWithFriends` in `user_preferences_settings.dart`

Impacted files:
* `abstract_user_preferences.dart`: minor refactoring
* `preferences_page.dart`: minor refactoring
* `user_preferences.dart`: minor refactoring
* `user_preferences_account.dart`: removed `UserPreferencesSection` and `_UserPreferencesAccountSubTitleSignOut` for simplification
* `user_preferences_attribute_group.dart`: refactored as not `AbstractUserPreferences`
* `user_preferences_connect.dart`: minor refactoring
* `user_preferences_contribute.dart`: minor refactoring
* `user_preferences_dev_mode.dart`: minor refactoring
* `user_preferences_faq.dart`: minor refactoring
* `user_preferences_food.dart`: minor refactoring
* `user_preferences_page.dart`: minor refactoring
* `user_preferences_settings.dart`: file was too big - moved code to new files+classes
  • Loading branch information
monsieurtanuki committed Sep 12, 2023
1 parent b530a37 commit 05d0490
Show file tree
Hide file tree
Showing 25 changed files with 685 additions and 902 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ class UserPreferences extends ChangeNotifier {
String? getDevModeString(final String tag) =>
_sharedPreferences.getString(tag);

Future<void> setActiveAttributeGroup(final String value) async =>
_sharedPreferences.setString(_TAG_ACTIVE_ATTRIBUTE_GROUP, value);
Future<void> setActiveAttributeGroup(final String value) async {
await _sharedPreferences.setString(_TAG_ACTIVE_ATTRIBUTE_GROUP, value);
notifyListeners();
}

String get activeAttributeGroup =>
_sharedPreferences.getString(_TAG_ACTIVE_ATTRIBUTE_GROUP) ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class _HelperState extends State<_Helper> {
pageData.addAll(
UserPreferencesFood(
productPreferences: productPreferences,
setState: setState,
context: context,
userPreferences: userPreferences,
appLocalizations: appLocalizations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ import 'package:smooth_app/themes/constant_icons.dart';
/// Abstraction of a display for the preference pages.
abstract class AbstractUserPreferences {
AbstractUserPreferences({
required this.setState,
required this.context,
required this.userPreferences,
required this.appLocalizations,
required this.themeData,
});

/// Function that refreshes the page.
final Function(Function()) setState;

final BuildContext context;
final UserPreferences userPreferences;
final AppLocalizations appLocalizations;
final ThemeData themeData;

/// Returns the type of the corresponding page if relevant, or else null.
PreferencePageType? getPreferencePageType();
@protected
PreferencePageType getPreferencePageType();

/// Title of the header, always visible.
String getTitleString();
Expand All @@ -45,6 +42,7 @@ abstract class AbstractUserPreferences {
child: getHeaderHelper(false),
);

@protected
Icon? getForwardIcon() => UserPreferencesListTile.getTintedIcon(
ConstantIcons.instance.getForwardIcon(),
context,
Expand All @@ -71,25 +69,10 @@ abstract class AbstractUserPreferences {
IconData getLeadingIconData();

/// Body of the content.
@protected
List<Widget> getBody();

/// Returns possibly the header and the body.
List<Widget> getContent({
final bool withHeader = true,
final bool withBody = true,
}) {
final List<Widget> result = <Widget>[];
if (withHeader) {
result.add(getHeader());
}
if (withBody) {
result.addAll(getBody());
}
return result;
}

/// Returns the action when we tap on the header.
@protected
Future<void> runHeaderAction() async => Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
Expand Down
Loading

0 comments on commit 05d0490

Please sign in to comment.