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 - new "preferences search" page from dev mode #4640

Merged
merged 2 commits into from
Sep 19, 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
@@ -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