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: #1160 - added a "delete account" option #1201

Merged
merged 1 commit into from
Mar 13, 2022
Merged
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
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