-
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add webview for account deletion * feat: add webview for account deletion * clean(preferences): remove useless reasonController * clean: fix variable naming * refactor: add deletionwebview state private and remove l10n from path segments
- Loading branch information
1 parent
fbab382
commit 61d9f39
Showing
11 changed files
with
207 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/smooth_app/lib/pages/preferences/account_deletion_webview.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; | ||
import 'package:smooth_app/helpers/user_management_helper.dart'; | ||
import 'package:smooth_app/widgets/smooth_scaffold.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
class AccountDeletionWebview extends StatefulWidget { | ||
@override | ||
State<AccountDeletionWebview> createState() => _AccountDeletionWebviewState(); | ||
} | ||
|
||
class _AccountDeletionWebviewState extends State<AccountDeletionWebview> { | ||
@override | ||
void initState() { | ||
super.initState(); | ||
// Enable virtual display. | ||
if (Platform.isAndroid) { | ||
WebView.platform = AndroidWebView(); | ||
} | ||
} | ||
|
||
String _getUrl() { | ||
final AppLocalizations appLocalizations = AppLocalizations.of(context); | ||
final String subject = appLocalizations.account_deletion_subject; | ||
|
||
final String? userId = OpenFoodAPIConfiguration.globalUser?.userId; | ||
|
||
final Uri uri = Uri( | ||
scheme: 'https', | ||
host: 'blog.openfoodfacts.org', | ||
pathSegments: <String>[ | ||
'en', | ||
'account-deletion', | ||
], | ||
queryParameters: <String, String>{ | ||
'your-subject': subject, | ||
if (userId != null && userId.isEmail) | ||
'your-mail': userId | ||
else if (userId != null) | ||
'your-name': userId | ||
}); | ||
|
||
return uri.toString(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SmoothScaffold( | ||
appBar: AppBar(), | ||
body: WebView( | ||
initialUrl: _getUrl(), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_email_sender/flutter_email_sender.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; | ||
|
@@ -11,11 +10,11 @@ import 'package:smooth_app/database/local_database.dart'; | |
import 'package:smooth_app/generic_lib/buttons/smooth_simple_button.dart'; | ||
import 'package:smooth_app/generic_lib/design_constants.dart'; | ||
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart'; | ||
import 'package:smooth_app/generic_lib/widgets/smooth_text_form_field.dart'; | ||
import 'package:smooth_app/helpers/analytics_helper.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/account_deletion_webview.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'; | ||
|
@@ -231,7 +230,6 @@ class _UserPreferencesPageState extends State<UserPreferencesSection> { | |
final ThemeData theme = Theme.of(context); | ||
final AppLocalizations appLocalizations = AppLocalizations.of(context); | ||
final Size size = MediaQuery.of(context).size; | ||
final TextEditingController reasonController = TextEditingController(); | ||
|
||
final List<Widget> result; | ||
|
||
|
@@ -306,47 +304,13 @@ class _UserPreferencesPageState extends State<UserPreferencesSection> { | |
const UserPreferencesListItemDivider(), | ||
_getListTile( | ||
appLocalizations.account_delete, | ||
() async { | ||
final String? reason = await showDialog<String>( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return SmoothAlertDialog( | ||
title: appLocalizations.account_delete, | ||
body: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: <Widget>[ | ||
Text(appLocalizations.account_delete_message), | ||
const SizedBox( | ||
height: 5, | ||
), | ||
SmoothTextFormField( | ||
type: TextFieldTypes.PLAIN_TEXT, | ||
textInputType: TextInputType.text, | ||
controller: reasonController, | ||
hintText: appLocalizations.reason), | ||
], | ||
), | ||
positiveAction: SmoothActionButton( | ||
text: appLocalizations.account_delete, | ||
onPressed: () => | ||
Navigator.pop(context, reasonController.text), | ||
), | ||
negativeAction: SmoothActionButton( | ||
text: appLocalizations.cancel, | ||
onPressed: () => Navigator.pop(context)), | ||
); | ||
}); | ||
if (reason != null) { | ||
final Email email = Email( | ||
body: | ||
'${appLocalizations.email_body_account_deletion(userId)} $reason', | ||
subject: appLocalizations.email_subject_account_deletion, | ||
recipients: <String>['[email protected]'], | ||
); | ||
|
||
await FlutterEmailSender.send(email); | ||
} | ||
() { | ||
Navigator.push<void>( | ||
context, | ||
MaterialPageRoute<void>( | ||
builder: (BuildContext context) => AccountDeletionWebview(), | ||
), | ||
); | ||
}, | ||
Icons.delete, | ||
), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/smooth_app/test/tests_utils/local_database_mock.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:smooth_app/database/local_database.dart'; | ||
|
||
class MockLocalDatabase extends Mock implements LocalDatabase {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters