Skip to content

Commit

Permalink
feat: 4513 - new "preferences search" page from dev mode (#4640)
Browse files Browse the repository at this point in the history
* feat: 4513 - new "preferences search page" from dev mode

Deleted files:
* `user_preferences_camera_sound.dart`
* `user_preferences_crash_reporting.dart`
* `user_preferences_haptic_feedback.dart`
* `user_preferences_send_anonymous.dart`

New files:
* `user_preferences_item.dart`: Item for preferences, with labels for pre-filtering and widget builder.
* `user_preferences_search_page.dart`: Search page for preferences, with TextField filter.

Impacted files:
* `abstract_user_preferences.dart`: new `getLabels` method for filtering; children are now `UserPreferencesItem` for filtering; minor refactoring.
* `user_preferences_account.dart`: children are now `UserPreferencesItem`; minor refactoring
* `user_preferences_advanced_settings.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_attribute_group.dart`: children are now `UserPreferencesItem`; minor refactoring
* `user_preferences_choose_accent_color.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_choose_app_theme.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_choose_text_color_contrast.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_connect.dart`: children are now `UserPreferencesItem`; minor refactoring
* `user_preferences_contribute.dart`: children are now `UserPreferencesItem`; minor refactoring
* `user_preferences_country_selector.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_dev_mode.dart`: children are now `UserPreferencesItem`; minor refactoring
* `user_preferences_faq.dart`: children are now `UserPreferencesItem`; minor refactoring
* `user_preferences_food.dart`: children are now `UserPreferencesItem`; minor refactoring
* `user_preferences_image_source.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_language_selector.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_page.dart`: moved `getUserPreferences` to `PreferencePageType`; minor refactoring
* `user_preferences_rate_us.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_settings.dart`: children are now `UserPreferencesItem`; minor refactoring
* `user_preferences_share_with_friends.dart`: added a static `UserPreferencesItem` getter
* `user_preferences_widgets.dart`: new classes `UserPreferencesItemSwitch` and `UserPreferencesItemTile`

* Update packages/smooth_app/lib/pages/preferences/user_preferences_page.dart
  • Loading branch information
monsieurtanuki committed Sep 19, 2023
1 parent e84826b commit 1096948
Show file tree
Hide file tree
Showing 26 changed files with 991 additions and 653 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/pages/preferences/user_preferences_item.dart';
import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';
import 'package:smooth_app/themes/constant_icons.dart';
Expand All @@ -23,6 +24,9 @@ abstract class AbstractUserPreferences {
@protected
PreferencePageType getPreferencePageType();

/// Title of the preference page.
String getPageTitleString() => getTitleString();

/// Title of the header, always visible.
String getTitleString();

Expand All @@ -35,7 +39,18 @@ abstract class AbstractUserPreferences {

/// Subtitle of the header, always visible.
@protected
Widget? getSubtitle();
String? getSubtitleString() => null;

/// Subtitle of the header, always visible.
@protected
Widget? getSubtitle() =>
getSubtitleString() == null ? null : Text(getSubtitleString()!);

List<String> getLabels() => <String>[
getPageTitleString(),
getTitleString(),
if (getSubtitleString() != null) getSubtitleString()!,
];

Widget getOnlyHeader() => InkWell(
onTap: () async => runHeaderAction(),
Expand Down Expand Up @@ -69,7 +84,7 @@ abstract class AbstractUserPreferences {
IconData getLeadingIconData();

/// Body of the content.
List<Widget> getBody();
List<UserPreferencesItem> getChildren();

/// Returns the action when we tap on the header.
@protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:smooth_app/helpers/launch_url_helper.dart';
import 'package:smooth_app/helpers/user_management_helper.dart';
import 'package:smooth_app/pages/preferences/abstract_user_preferences.dart';
import 'package:smooth_app/pages/preferences/account_deletion_webview.dart';
import 'package:smooth_app/pages/preferences/user_preferences_item.dart';
import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
Expand Down Expand Up @@ -42,31 +43,31 @@ class UserPreferencesAccount extends AbstractUserPreferences {
String? _getUserId() => OpenFoodAPIConfiguration.globalUser?.userId;

@override
Widget getTitle() {
String getTitleString() {
final String? userId = _getUserId();
final String title;

if (userId == null) {
title = appLocalizations.user_profile_title_guest;
} else if (userId.isEmail) {
title = appLocalizations.user_profile_title_id_email(userId);
} else {
title = appLocalizations.user_profile_title_id_default(userId);
return appLocalizations.user_profile_title_guest;
}

return Text(
title,
style: Theme.of(context).textTheme.displayMedium,
);
if (userId.isEmail) {
return appLocalizations.user_profile_title_id_email(userId);
}
return appLocalizations.user_profile_title_id_default(userId);
}

@override
String getTitleString() => appLocalizations.myPreferences_profile_title;
String getPageTitleString() => appLocalizations.myPreferences_profile_title;

@override
Widget? getSubtitle() => _isUserConnected()
? Text(appLocalizations.myPreferences_profile_subtitle)
: Text(appLocalizations.user_profile_subtitle_guest);
String getSubtitleString() => _isUserConnected()
? appLocalizations.myPreferences_profile_subtitle
: appLocalizations.user_profile_subtitle_guest;

@override
List<String> getLabels() => <String>[
...super.getLabels(),
if (_getUserId() == null) appLocalizations.sign_in,
];

@override
IconData getLeadingIconData() => Icons.face;
Expand Down Expand Up @@ -127,30 +128,33 @@ class UserPreferencesAccount extends AbstractUserPreferences {
);

@override
List<Widget> getBody() {
List<UserPreferencesItem> getChildren() {
if (OpenFoodAPIConfiguration.globalUser == null) {
// No credentials
final Size size = MediaQuery.of(context).size;
return <Widget>[
Center(
child: ElevatedButton(
onPressed: () async => _goToLoginPage(),
style: ButtonStyle(
minimumSize: MaterialStateProperty.all<Size>(
Size(size.width * 0.5, themeData.buttonTheme.height + 10),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: CIRCULAR_BORDER_RADIUS,
return <UserPreferencesItem>[
UserPreferencesItemSimple(
labels: <String>[appLocalizations.sign_in],
builder: (_) => Center(
child: ElevatedButton(
onPressed: () async => _goToLoginPage(),
style: ButtonStyle(
minimumSize: MaterialStateProperty.all<Size>(
Size(size.width * 0.5, themeData.buttonTheme.height + 10),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: CIRCULAR_BORDER_RADIUS,
),
),
),
),
child: Text(
appLocalizations.sign_in,
style: themeData.textTheme.bodyMedium?.copyWith(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: themeData.colorScheme.onPrimary,
child: Text(
appLocalizations.sign_in,
style: themeData.textTheme.bodyMedium?.copyWith(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: themeData.colorScheme.onPrimary,
),
),
),
),
Expand All @@ -161,7 +165,7 @@ class UserPreferencesAccount extends AbstractUserPreferences {
final LocalDatabase localDatabase = context.read<LocalDatabase>();
// Credentials
final String userId = OpenFoodAPIConfiguration.globalUser!.userId;
return <Widget>[
return <UserPreferencesItem>[
_buildProductQueryTile(
productQuery: PagedUserProductQuery(
userId: userId,
Expand Down Expand Up @@ -299,7 +303,7 @@ class UserPreferencesAccount extends AbstractUserPreferences {
}
}

Widget _buildProductQueryTile({
UserPreferencesItem _buildProductQueryTile({
required final PagedProductQuery productQuery,
required final String title,
required final IconData iconData,
Expand All @@ -320,42 +324,45 @@ class UserPreferencesAccount extends AbstractUserPreferences {
myCount: myCount,
);

Widget _getListTile(
UserPreferencesItem _getListTile(
final String title,
final VoidCallback onTap,
final IconData leading, {
final Future<int?>? myCount,
}) =>
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
elevation: 5,
color: Theme.of(context).cardColor,
child: UserPreferencesListTile(
title: Text(title),
onTap: onTap,
UserPreferencesItemSimple(
labels: <String>[title],
builder: (_) => Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
leading: UserPreferencesListTile.getTintedIcon(leading, context),
trailing: myCount == null
? null
: FutureBuilder<int?>(
future: myCount,
builder:
(BuildContext context, AsyncSnapshot<int?> snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const SizedBox(
height: LARGE_SPACE,
width: LARGE_SPACE,
child: CircularProgressIndicator.adaptive());
}
return snapshot.data == null
? EMPTY_WIDGET
: Text(snapshot.data.toString());
},
),
elevation: 5,
color: Theme.of(context).cardColor,
child: UserPreferencesListTile(
title: Text(title),
onTap: onTap,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
leading: UserPreferencesListTile.getTintedIcon(leading, context),
trailing: myCount == null
? null
: FutureBuilder<int?>(
future: myCount,
builder:
(BuildContext context, AsyncSnapshot<int?> snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const SizedBox(
height: LARGE_SPACE,
width: LARGE_SPACE,
child: CircularProgressIndicator.adaptive());
}
return snapshot.data == null
? EMPTY_WIDGET
: Text(snapshot.data.toString());
},
),
),
),
);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import 'package:app_settings/app_settings.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_app/pages/preferences/user_preferences_item.dart';
import 'package:smooth_app/pages/preferences/user_preferences_widgets.dart';

class UserPreferencesAdvancedSettings extends StatelessWidget {
const UserPreferencesAdvancedSettings();

static UserPreferencesItem getUserPreferencesItem(
final BuildContext context,
) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return UserPreferencesItemSimple(
labels: <String>[
appLocalizations.native_app_settings,
appLocalizations.native_app_description,
],
builder: (_) => const UserPreferencesAdvancedSettings(),
);
}

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
Expand Down
Loading

0 comments on commit 1096948

Please sign in to comment.