Skip to content

Commit

Permalink
feat: #1160 - added a "delete account" option (#1201)
Browse files Browse the repository at this point in the history
Impacted file:
* `user_preferences_profile.dart`: added a "delete account" option; had to refactor the UI
  • Loading branch information
monsieurtanuki authored Mar 13, 2022
1 parent 2ac737e commit 21d7cf5
Showing 1 changed file with 31 additions and 48 deletions.
79 changes: 31 additions & 48 deletions packages/smooth_app/lib/pages/user_preferences_profile.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:mailto/mailto.dart';
import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_action_button.dart';
Expand All @@ -10,6 +11,7 @@ import 'package:smooth_app/helpers/user_management_helper.dart';
import 'package:smooth_app/pages/abstract_user_preferences.dart';
import 'package:smooth_app/pages/onboarding/country_selector.dart';
import 'package:smooth_app/pages/user_management/login_page.dart';
import 'package:url_launcher/url_launcher.dart';

/// Collapsed/expanded display of profile for the preferences page.
class UserPreferencesProfile extends AbstractUserPreferences {
Expand Down Expand Up @@ -53,55 +55,36 @@ class UserPreferencesProfile extends AbstractUserPreferences {

//Credentials exist
if (OpenFoodAPIConfiguration.globalUser != null) {
final String userId = OpenFoodAPIConfiguration.globalUser!.userId;
result.add(
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
ElevatedButton.icon(
onPressed: () => LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/editor/${OpenFoodAPIConfiguration.globalUser!.userId}',
true,
),
label: Text(
appLocalizations.view_profile,
style: theme.textTheme.bodyText2?.copyWith(
fontSize: 18.0,
color: theme.colorScheme.surface,
),
),
icon: const Icon(Icons.open_in_new),
style: ButtonStyle(
minimumSize: MaterialStateProperty.all<Size>(
Size(size.width * 0.33, theme.buttonTheme.height + 10),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: CIRCULAR_BORDER_RADIUS,
),
),
),
),
ElevatedButton(
onPressed: () => _confirmLogout(context),
child: Text(
appLocalizations.sign_out,
style: theme.textTheme.bodyText2?.copyWith(
fontSize: 18.0,
color: theme.colorScheme.surface,
),
),
style: ButtonStyle(
minimumSize: MaterialStateProperty.all<Size>(
Size(size.width * 0.33, theme.buttonTheme.height + 10),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: CIRCULAR_BORDER_RADIUS,
),
),
),
),
],
ListTile(
onTap: () async => LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/editor/$userId',
true,
),
title: Text(appLocalizations.view_profile),
leading: const Icon(Icons.open_in_new),
),
);
result.add(
ListTile(
onTap: () => _confirmLogout(context),
title: Text(appLocalizations.sign_out),
leading: const Icon(Icons.clear),
),
);
result.add(
ListTile(
onTap: () async {
final Mailto mailtoLink = Mailto(
to: <String>['contact@openfoodfacts.org'],
subject: 'Delete account', // TODO(monsieurtanuki): localize
body: 'Hi there, please delete my openfoodfacts account: $userId',
);
await launch('$mailtoLink');
},
title: const Text('Delete account'),
leading: const Icon(Icons.delete),
),
);
} else {
Expand Down

0 comments on commit 21d7cf5

Please sign in to comment.