ente/mobile/lib/ui/account/recovery_page.dart

172 lines
5.9 KiB
Dart
Raw Normal View History

2021-04-01 14:26:08 +00:00
import 'dart:ui';
2021-03-30 12:13:13 +00:00
import 'package:flutter/material.dart';
2021-04-01 14:26:08 +00:00
import 'package:photos/core/configuration.dart';
2023-04-04 17:02:16 +00:00
import "package:photos/generated/l10n.dart";
import "package:photos/theme/ente_theme.dart";
import 'package:photos/ui/account/password_entry_page.dart';
2022-07-03 10:09:01 +00:00
import 'package:photos/ui/common/dynamic_fab.dart';
2021-04-01 14:26:08 +00:00
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/toast_util.dart';
2021-03-30 12:13:13 +00:00
2021-04-01 14:26:08 +00:00
class RecoveryPage extends StatefulWidget {
const RecoveryPage({Key? key}) : super(key: key);
2021-03-30 12:13:13 +00:00
2021-04-01 14:26:08 +00:00
@override
2022-07-03 09:45:00 +00:00
State<RecoveryPage> createState() => _RecoveryPageState();
2021-04-01 14:26:08 +00:00
}
class _RecoveryPageState extends State<RecoveryPage> {
final _recoveryKey = TextEditingController();
2021-03-30 12:13:13 +00:00
@override
Widget build(BuildContext context) {
2022-06-15 06:48:23 +00:00
final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100;
FloatingActionButtonLocation? fabLocation() {
2022-06-15 06:48:23 +00:00
if (isKeypadOpen) {
return null;
} else {
return FloatingActionButtonLocation.centerFloat;
}
}
2021-03-30 12:13:13 +00:00
return Scaffold(
2022-06-15 06:48:23 +00:00
resizeToAvoidBottomInset: isKeypadOpen,
2021-03-30 12:13:13 +00:00
appBar: AppBar(
elevation: 0,
leading: IconButton(
2022-07-04 06:02:17 +00:00
icon: const Icon(Icons.arrow_back),
color: Theme.of(context).iconTheme.color,
onPressed: () {
Navigator.of(context).pop();
},
2021-03-30 12:13:13 +00:00
),
),
floatingActionButton: DynamicFAB(
2022-06-15 06:48:23 +00:00
isKeypadOpen: isKeypadOpen,
2022-06-11 08:23:52 +00:00
isFormValid: _recoveryKey.text.isNotEmpty,
2023-04-04 17:02:16 +00:00
buttonText: S.of(context).recoverButton,
2022-06-11 08:23:52 +00:00
onPressedFunction: () async {
FocusScope.of(context).unfocus();
2023-04-04 17:02:16 +00:00
final dialog =
createProgressDialog(context, S.of(context).decrypting);
2022-06-11 08:23:52 +00:00
await dialog.show();
try {
await Configuration.instance.recover(_recoveryKey.text.trim());
await dialog.hide();
2023-04-04 17:02:16 +00:00
showShortToast(context, S.of(context).recoverySuccessful);
2023-12-16 21:04:26 +00:00
// ignore: unawaited_futures
2022-06-11 08:23:52 +00:00
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (BuildContext context) {
return const PopScope(
canPop: false,
child: PasswordEntryPage(
2022-06-11 08:23:52 +00:00
mode: PasswordEntryMode.reset,
),
);
},
),
);
} catch (e) {
await dialog.hide();
2023-04-04 17:02:16 +00:00
String errMessage = S.of(context).incorrectRecoveryKeyBody;
2022-06-11 08:23:52 +00:00
if (e is AssertionError) {
errMessage = '$errMessage : ${e.message}';
}
2023-12-16 21:04:26 +00:00
// ignore: unawaited_futures
2023-04-04 17:02:16 +00:00
showErrorDialog(
context,
S.of(context).incorrectRecoveryKeyTitle,
errMessage,
);
2022-06-11 08:23:52 +00:00
}
},
),
2022-06-15 06:48:23 +00:00
floatingActionButtonLocation: fabLocation(),
2022-05-30 15:43:33 +00:00
floatingActionButtonAnimator: NoScalingAnimation(),
2021-03-30 12:13:13 +00:00
body: Column(
children: [
Expanded(
child: ListView(
children: [
Padding(
2022-07-03 09:45:00 +00:00
padding:
const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
2022-06-11 08:23:52 +00:00
child: Text(
2023-04-04 17:02:16 +00:00
S.of(context).forgotPassword,
2023-06-13 06:41:31 +00:00
style: Theme.of(context).textTheme.headlineMedium,
2022-06-11 08:23:52 +00:00
),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
child: TextFormField(
decoration: InputDecoration(
filled: true,
fillColor: getEnteColorScheme(context).fillFaint,
2023-04-04 17:02:16 +00:00
hintText: S.of(context).enterYourRecoveryKey,
2022-07-04 06:02:17 +00:00
contentPadding: const EdgeInsets.all(20),
border: UnderlineInputBorder(
2022-06-11 08:23:52 +00:00
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(6),
),
),
2022-07-04 06:02:17 +00:00
style: const TextStyle(
fontSize: 14,
2022-07-04 06:02:17 +00:00
fontFeatures: [FontFeature.tabularFigures()],
),
controller: _recoveryKey,
autofocus: false,
autocorrect: false,
keyboardType: TextInputType.multiline,
maxLines: null,
onChanged: (_) {
setState(() {});
},
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 18),
child: Divider(
thickness: 1,
color: getEnteColorScheme(context).strokeFaint,
),
),
Row(
children: [
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
showErrorDialog(
context,
2023-04-04 17:02:16 +00:00
S.of(context).sorry,
S.of(context).noRecoveryKeyNoDecryption,
);
},
child: Container(
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Center(
child: Text(
2023-04-04 17:02:16 +00:00
S.of(context).noRecoveryKey,
2023-06-13 06:41:31 +00:00
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontSize: 14,
decoration: TextDecoration.underline,
),
),
),
),
),
],
2021-04-01 14:26:08 +00:00
),
],
2021-04-01 14:26:08 +00:00
),
),
2021-03-30 12:13:13 +00:00
],
),
);
}
}