2022-03-08 19:43:51 +00:00
|
|
|
import 'package:expandable/expandable.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2021-04-19 09:35:22 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-07-28 15:41:45 +00:00
|
|
|
import 'package:flutter_sodium/flutter_sodium.dart';
|
2021-08-04 17:33:59 +00:00
|
|
|
import 'package:photos/core/configuration.dart';
|
2021-07-28 15:41:45 +00:00
|
|
|
import 'package:photos/services/user_service.dart';
|
2021-08-04 17:33:59 +00:00
|
|
|
import 'package:photos/ui/app_lock.dart';
|
2021-07-28 18:06:30 +00:00
|
|
|
import 'package:photos/ui/change_email_dialog.dart';
|
2021-07-28 15:41:45 +00:00
|
|
|
import 'package:photos/ui/password_entry_page.dart';
|
2021-08-21 08:47:34 +00:00
|
|
|
import 'package:photos/ui/payment/subscription.dart';
|
2022-04-06 17:41:24 +00:00
|
|
|
import 'package:photos/ui/recovery_key_page.dart';
|
2022-03-08 19:43:51 +00:00
|
|
|
import 'package:photos/ui/settings/common_settings.dart';
|
2021-04-19 09:35:22 +00:00
|
|
|
import 'package:photos/ui/settings/settings_section_title.dart';
|
|
|
|
import 'package:photos/ui/settings/settings_text_item.dart';
|
2021-07-28 15:41:45 +00:00
|
|
|
import 'package:photos/utils/auth_util.dart';
|
|
|
|
import 'package:photos/utils/dialog_util.dart';
|
2022-04-06 17:41:24 +00:00
|
|
|
import 'package:photos/utils/navigation_util.dart';
|
2021-07-28 15:41:45 +00:00
|
|
|
import 'package:photos/utils/toast_util.dart';
|
2021-04-19 09:35:22 +00:00
|
|
|
|
|
|
|
class AccountSectionWidget extends StatefulWidget {
|
|
|
|
AccountSectionWidget({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
AccountSectionWidgetState createState() => AccountSectionWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class AccountSectionWidgetState extends State<AccountSectionWidget> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-03-08 19:43:51 +00:00
|
|
|
return ExpandablePanel(
|
|
|
|
header: SettingsSectionTitle("Account"),
|
|
|
|
collapsed: Container(),
|
|
|
|
expanded: _getSectionOptions(context),
|
|
|
|
theme: getExpandableTheme(context),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Column _getSectionOptions(BuildContext context) {
|
2021-07-27 14:51:45 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
GestureDetector(
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
onTap: () async {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(
|
2021-04-19 09:35:22 +00:00
|
|
|
builder: (BuildContext context) {
|
2021-08-21 08:47:34 +00:00
|
|
|
return getSubscriptionPage();
|
2021-04-19 09:35:22 +00:00
|
|
|
},
|
2021-07-27 14:51:45 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: SettingsTextItem(
|
2022-03-08 19:43:51 +00:00
|
|
|
text: "Subscription plan", icon: Icons.navigate_next),
|
2021-07-27 14:51:45 +00:00
|
|
|
),
|
2022-03-08 19:43:51 +00:00
|
|
|
SectionOptionDivider,
|
2021-07-28 15:41:45 +00:00
|
|
|
GestureDetector(
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
onTap: () async {
|
2021-08-04 17:33:59 +00:00
|
|
|
AppLock.of(context).setEnabled(false);
|
2021-11-27 06:15:07 +00:00
|
|
|
String reason = "please authenticate to view your recovery key";
|
2021-11-27 06:19:05 +00:00
|
|
|
final result = await requestAuthentication(reason);
|
2021-08-04 17:33:59 +00:00
|
|
|
AppLock.of(context)
|
|
|
|
.setEnabled(Configuration.instance.shouldShowLockScreen());
|
2021-07-28 15:41:45 +00:00
|
|
|
if (!result) {
|
2021-11-27 06:15:07 +00:00
|
|
|
showToast(reason);
|
2021-07-28 15:41:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String recoveryKey;
|
|
|
|
try {
|
|
|
|
recoveryKey = await _getOrCreateRecoveryKey();
|
|
|
|
} catch (e) {
|
|
|
|
showGenericErrorDialog(context);
|
|
|
|
return;
|
|
|
|
}
|
2022-04-06 17:41:24 +00:00
|
|
|
routeToPage(
|
|
|
|
context,
|
|
|
|
RecoveryKeyPage(recoveryKey, "OK",
|
|
|
|
showAppBar: true, onDone: () {}));
|
2021-07-28 15:41:45 +00:00
|
|
|
},
|
|
|
|
child:
|
2022-04-06 17:51:08 +00:00
|
|
|
SettingsTextItem(text: "Recovery Key", icon: Icons.navigate_next),
|
2021-07-28 15:41:45 +00:00
|
|
|
),
|
2022-03-08 19:43:51 +00:00
|
|
|
SectionOptionDivider,
|
2021-07-28 18:06:30 +00:00
|
|
|
GestureDetector(
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
onTap: () async {
|
2021-08-04 17:33:59 +00:00
|
|
|
AppLock.of(context).setEnabled(false);
|
2021-11-27 06:15:07 +00:00
|
|
|
String reason = "please authenticate to change your email";
|
2021-11-27 06:19:05 +00:00
|
|
|
final result = await requestAuthentication(reason);
|
2021-08-04 17:33:59 +00:00
|
|
|
AppLock.of(context)
|
|
|
|
.setEnabled(Configuration.instance.shouldShowLockScreen());
|
|
|
|
if (!result) {
|
2021-11-27 06:15:07 +00:00
|
|
|
showToast(reason);
|
2021-08-04 17:33:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-28 18:06:30 +00:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ChangeEmailDialog();
|
|
|
|
},
|
|
|
|
barrierColor: Colors.black.withOpacity(0.85),
|
|
|
|
barrierDismissible: false,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child:
|
2022-03-08 19:43:51 +00:00
|
|
|
SettingsTextItem(text: "Change email", icon: Icons.navigate_next),
|
2021-07-28 18:06:30 +00:00
|
|
|
),
|
2022-03-08 19:43:51 +00:00
|
|
|
SectionOptionDivider,
|
2021-07-28 15:41:45 +00:00
|
|
|
GestureDetector(
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
onTap: () async {
|
2021-08-04 17:33:59 +00:00
|
|
|
AppLock.of(context).setEnabled(false);
|
2021-11-27 06:15:07 +00:00
|
|
|
String reason = "please authenticate to change your password";
|
2021-11-27 06:19:05 +00:00
|
|
|
final result = await requestAuthentication(reason);
|
2021-08-04 17:33:59 +00:00
|
|
|
AppLock.of(context)
|
|
|
|
.setEnabled(Configuration.instance.shouldShowLockScreen());
|
2021-07-28 15:41:45 +00:00
|
|
|
if (!result) {
|
2021-11-27 06:15:07 +00:00
|
|
|
showToast(reason);
|
2021-07-28 15:41:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return PasswordEntryPage(
|
|
|
|
mode: PasswordEntryMode.update,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: SettingsTextItem(
|
2022-03-12 14:16:04 +00:00
|
|
|
text: "Change password", icon: Icons.navigate_next),
|
2021-07-27 14:51:45 +00:00
|
|
|
),
|
|
|
|
],
|
2021-04-19 09:35:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:41:45 +00:00
|
|
|
Future<String> _getOrCreateRecoveryKey() async {
|
|
|
|
return Sodium.bin2hex(
|
|
|
|
await UserService.instance.getOrCreateRecoveryKey(context));
|
2021-04-19 09:35:22 +00:00
|
|
|
}
|
|
|
|
}
|