Skip to content

Commit

Permalink
fix: #2776 - more standard user preferences app bar (#2780)
Browse files Browse the repository at this point in the history
Impacted files:
* golden files
* `user_preferences_account.dart`: unrelated uniformization of list tile display in preferences
* `user_preferences_food.dart`: unrelated uniformization of list tile display in preferences
* `user_preferences_page.dart`: removed the sliver effect
  • Loading branch information
monsieurtanuki committed Aug 12, 2022
1 parent 9e11f50 commit 4abe9fe
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 57 deletions.
Expand Up @@ -13,6 +13,7 @@ import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
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/user_preferences_list_tile.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';
import 'package:smooth_app/pages/preferences/user_preferences_widgets.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
Expand Down Expand Up @@ -285,27 +286,28 @@ class _UserPreferencesPageState extends State<UserPreferencesSection> {
localDatabase: localDatabase,
),
const UserPreferencesListItemDivider(),
ListTile(
onTap: () async => LaunchUrlHelper.launchURL(
_getListTile(
appLocalizations.view_profile,
() async => LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/editor/$userId',
true,
),
title: Text(appLocalizations.view_profile),
leading: const Icon(Icons.open_in_new),
Icons.open_in_new,
),
const UserPreferencesListItemDivider(),
ListTile(
onTap: () async {
_getListTile(
appLocalizations.sign_out,
() async {
if (await _confirmLogout(context) == true) {
Navigator.pop(context);
}
},
title: Text(appLocalizations.sign_out),
leading: const Icon(Icons.clear),
Icons.clear,
),
const UserPreferencesListItemDivider(),
ListTile(
onTap: () async {
_getListTile(
appLocalizations.account_delete,
() async {
final Email email = Email(
body: appLocalizations.email_body_account_deletion(userId),
subject: appLocalizations.email_subject_account_deletion,
Expand All @@ -314,8 +316,7 @@ class _UserPreferencesPageState extends State<UserPreferencesSection> {

await FlutterEmailSender.send(email);
},
title: Text(appLocalizations.account_delete),
leading: const Icon(Icons.delete),
Icons.delete,
),
const UserPreferencesListItemDivider(),
];
Expand Down Expand Up @@ -367,14 +368,25 @@ class _UserPreferencesPageState extends State<UserPreferencesSection> {
required final BuildContext context,
required final LocalDatabase localDatabase,
}) =>
ListTile(
onTap: () async => ProductQueryPageHelper().openBestChoice(
_getListTile(
title,
() async => ProductQueryPageHelper().openBestChoice(
name: title,
localDatabase: localDatabase,
productQuery: productQuery,
context: context,
),
iconData,
);

Widget _getListTile(
final String title,
final VoidCallback onTap,
final IconData leading,
) =>
UserPreferencesListTile(
title: Text(title),
leading: Icon(iconData),
onTap: onTap,
leading: UserPreferencesListTile.getTintedIcon(leading, context),
);
}
Expand Up @@ -8,6 +8,7 @@ import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/pages/preferences/abstract_user_preferences.dart';
import 'package:smooth_app/pages/preferences/user_preferences_attribute_group.dart';
import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';

/// Collapsed/expanded display of attribute groups for the preferences page.
Expand Down Expand Up @@ -60,8 +61,11 @@ class UserPreferencesFood extends AbstractUserPreferences {
List<Widget> getBody() {
final List<Widget> result = <Widget>[
// we don't want this on the onboarding
ListTile(
leading: const Icon(Icons.rotate_left),
UserPreferencesListTile(
leading: UserPreferencesListTile.getTintedIcon(
Icons.rotate_left,
context,
),
title: Text(appLocalizations.reset_food_prefs),
onTap: () async => _confirmReset(),
),
Expand Down
Expand Up @@ -133,52 +133,23 @@ class _UserPreferencesPageState extends State<UserPreferencesPage>
body: Scrollbar(child: list),
);
}
final MediaQueryData mediaQueryData = MediaQuery.of(context);
final bool dark = Theme.of(context).brightness == Brightness.dark;
// TODO(monsieurtanuki): experimental - find a better value
const double titleHeightInExpandedMode = 50;
final double backgroundHeight = mediaQueryData.size.height * .20;
// TODO(monsieurtanuki): get rid of explicit foregroundColor when appbartheme colors are correct
final Color? foregroundColor = dark ? null : Colors.black;
final double backgroundHeight = MediaQuery.of(context).size.height * .20;
children.insert(
0,
Container(
color: dark ? null : headerColor,
padding: const EdgeInsets.symmetric(vertical: SMALL_SPACE),
child: SvgPicture.asset(headerAsset, height: backgroundHeight),
),
);
return SmoothScaffold(
statusBarBackgroundColor: dark ? null : headerColor,
brightness: Brightness.light,
contentBehindStatusBar: false,
spaceBehindStatusBar: false,
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
pinned: true,
snap: false,
floating: false,
stretch: true,
backgroundColor: dark ? null : headerColor,
expandedHeight: backgroundHeight + titleHeightInExpandedMode,
foregroundColor: foregroundColor,
flexibleSpace: FlexibleSpaceBar(
title: Text(
appBarTitle,
style: TextStyle(color: foregroundColor),
),
background: Padding(
padding: const EdgeInsetsDirectional.only(
bottom: titleHeightInExpandedMode,
),
child: SvgPicture.asset(
headerAsset,
height: backgroundHeight,
),
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) => children[index],
childCount: children.length,
),
),
],
),
appBar: AppBar(title: Text(appBarTitle)),
body: ListView(children: children),
);
}

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4abe9fe

Please sign in to comment.