Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 4513 - user preferences pages simple refactoring #4620

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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