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";
|
2022-07-01 14:18:05 +00:00
|
|
|
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 {
|
2022-12-30 12:10:17 +00:00
|
|
|
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;
|
2022-12-30 12:10:17 +00:00
|
|
|
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(
|
2022-04-11 14:38:52 +00:00
|
|
|
elevation: 0,
|
|
|
|
leading: IconButton(
|
2022-07-04 06:02:17 +00:00
|
|
|
icon: const Icon(Icons.arrow_back),
|
2022-04-11 14:38:52 +00:00
|
|
|
color: Theme.of(context).iconTheme.color,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2021-03-30 12:13:13 +00:00
|
|
|
),
|
|
|
|
),
|
2022-04-21 09:43:22 +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 {
|
2022-06-15 12:44:23 +00:00
|
|
|
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 WillPopScope(
|
|
|
|
onWillPop: () async => false,
|
2022-07-04 08:43:01 +00:00
|
|
|
child: const 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}';
|
2022-04-11 14:38:52 +00:00
|
|
|
}
|
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: [
|
2022-04-11 14:38:52 +00:00
|
|
|
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
|
|
|
),
|
2022-04-11 14:38:52 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
|
|
|
|
child: TextFormField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
filled: true,
|
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),
|
2022-04-11 14:38:52 +00:00
|
|
|
border: UnderlineInputBorder(
|
2022-06-11 08:23:52 +00:00
|
|
|
borderSide: BorderSide.none,
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
),
|
2022-04-11 14:38:52 +00:00
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
style: const TextStyle(
|
2022-04-11 14:38:52 +00:00
|
|
|
fontSize: 14,
|
2022-07-04 06:02:17 +00:00
|
|
|
fontFeatures: [FontFeature.tabularFigures()],
|
2022-04-11 14:38:52 +00:00
|
|
|
),
|
|
|
|
controller: _recoveryKey,
|
|
|
|
autofocus: false,
|
|
|
|
autocorrect: false,
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
maxLines: null,
|
|
|
|
onChanged: (_) {
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 18),
|
2022-04-11 14:38:52 +00:00
|
|
|
child: Divider(
|
|
|
|
thickness: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
GestureDetector(
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
onTap: () {
|
2021-11-12 17:40:56 +00:00
|
|
|
showErrorDialog(
|
2022-04-11 14:38:52 +00:00
|
|
|
context,
|
2023-04-04 17:02:16 +00:00
|
|
|
S.of(context).sorry,
|
|
|
|
S.of(context).noRecoveryKeyNoDecryption,
|
2022-04-11 14:38:52 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Container(
|
2022-07-04 06:02:17 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
2022-04-11 14:38:52 +00:00
|
|
|
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,
|
|
|
|
),
|
2022-04-11 14:38:52 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2021-04-01 14:26:08 +00:00
|
|
|
),
|
2022-04-11 14:38:52 +00:00
|
|
|
],
|
2021-04-01 14:26:08 +00:00
|
|
|
),
|
|
|
|
),
|
2021-03-30 12:13:13 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|