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

222 lines
7.8 KiB
Dart
Raw Normal View History

2020-08-25 05:51:56 +00:00
import 'package:flutter/material.dart';
2022-06-07 04:40:29 +00:00
import 'package:photos/ente_theme_data.dart';
import "package:photos/generated/l10n.dart";
2020-10-03 17:56:18 +00:00
import 'package:photos/services/user_service.dart';
import "package:photos/theme/ente_theme.dart";
2022-07-03 10:09:01 +00:00
import 'package:photos/ui/common/dynamic_fab.dart';
import 'package:step_progress_indicator/step_progress_indicator.dart';
2023-04-19 04:49:16 +00:00
import "package:styled_text/styled_text.dart";
2020-08-25 05:51:56 +00:00
class OTTVerificationPage extends StatefulWidget {
2021-07-28 18:06:30 +00:00
final String email;
final bool isChangeEmail;
2022-04-09 05:40:56 +00:00
final bool isCreateAccountScreen;
2023-07-18 12:05:30 +00:00
final bool isResetPasswordScreen;
2021-07-28 18:06:30 +00:00
const OTTVerificationPage(
2021-07-28 18:06:30 +00:00
this.email, {
this.isChangeEmail = false,
2022-06-23 12:12:19 +00:00
this.isCreateAccountScreen = false,
this.isResetPasswordScreen = false,
Key? key,
2021-07-28 18:06:30 +00:00
}) : super(key: key);
2020-08-25 05:51:56 +00:00
@override
2022-07-03 09:45:00 +00:00
State<OTTVerificationPage> createState() => _OTTVerificationPageState();
2020-08-25 05:51:56 +00:00
}
class _OTTVerificationPageState extends State<OTTVerificationPage> {
final _verificationCodeController = TextEditingController();
@override
Widget build(BuildContext context) {
2022-06-15 06:48:23 +00:00
final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100;
FloatingActionButtonLocation? fabLocation() {
if (isKeypadOpen) {
return null;
} else {
return FloatingActionButtonLocation.centerFloat;
}
}
2020-08-25 05:51:56 +00:00
return Scaffold(
2022-06-15 06:48:23 +00:00
resizeToAvoidBottomInset: isKeypadOpen,
2020-08-25 05:51:56 +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();
},
),
2022-04-09 05:40:56 +00:00
title: widget.isCreateAccountScreen
? Material(
type: MaterialType.transparency,
child: StepProgressIndicator(
totalSteps: 4,
currentStep: 2,
2022-07-12 06:30:02 +00:00
selectedColor: Theme.of(context).colorScheme.greenAlternative,
2022-07-04 06:02:17 +00:00
roundedEdges: const Radius.circular(10),
unselectedColor:
Theme.of(context).colorScheme.stepProgressUnselectedColor,
2022-06-07 04:40:29 +00:00
),
2022-04-09 05:40:56 +00:00
)
: null,
2020-08-25 05:51:56 +00:00
),
body: _getBody(),
floatingActionButton: DynamicFAB(
key: const ValueKey("verifyOttButton"),
isKeypadOpen: isKeypadOpen,
2022-12-30 15:42:03 +00:00
isFormValid: _verificationCodeController.text.isNotEmpty,
buttonText: S.of(context).verify,
onPressedFunction: () {
if (widget.isChangeEmail) {
UserService.instance.changeEmail(
2022-06-11 08:23:52 +00:00
context,
widget.email,
_verificationCodeController.text,
);
} else {
UserService.instance.verifyEmail(
context,
_verificationCodeController.text,
isResettingPasswordScreen: widget.isResetPasswordScreen,
);
}
FocusScope.of(context).unfocus();
},
),
floatingActionButtonLocation: fabLocation(),
2022-05-30 15:43:33 +00:00
floatingActionButtonAnimator: NoScalingAnimation(),
2020-08-25 05:51:56 +00:00
);
}
Widget _getBody() {
return ListView(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(20, 30, 20, 15),
2022-06-11 08:23:52 +00:00
child: Text(
S.of(context).verifyEmail,
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.symmetric(horizontal: 20, vertical: 10),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
2022-06-19 10:04:53 +00:00
padding: const EdgeInsets.fromLTRB(0, 0, 0, 12),
2023-04-19 04:49:16 +00:00
child: StyledText(
text: S.of(context).weHaveSendEmailTo(widget.email),
style: Theme.of(context)
.textTheme
2023-06-13 06:41:31 +00:00
.titleMedium!
2023-04-19 04:49:16 +00:00
.copyWith(fontSize: 14),
tags: {
'green': StyledTextTag(
style: TextStyle(
color: Theme.of(context)
.colorScheme
.greenAlternative,
),
),
},
2022-05-03 11:53:18 +00:00
),
),
widget.isResetPasswordScreen
? Text(
S.of(context).toResetVerifyEmail,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(fontSize: 14),
)
: Text(
S.of(context).checkInboxAndSpamFolder,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(fontSize: 14),
),
],
),
),
SizedBox(
2022-06-19 10:04:53 +00:00
width: MediaQuery.of(context).size.width * 0.2,
height: 1,
2023-08-19 11:39:56 +00:00
),
],
2020-08-25 05:51:56 +00:00
),
),
Padding(
2022-06-19 10:04:53 +00:00
padding: const EdgeInsets.fromLTRB(20, 16, 20, 16),
child: TextFormField(
key: const ValueKey("ottVerificationInputField"),
2023-06-13 06:41:31 +00:00
style: Theme.of(context).textTheme.titleMedium,
decoration: InputDecoration(
filled: true,
hintText: S.of(context).tapToEnterCode,
2022-07-04 06:02:17 +00:00
contentPadding: const EdgeInsets.all(15),
border: UnderlineInputBorder(
2022-06-11 08:23:52 +00:00
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(6),
),
fillColor: getEnteColorScheme(context).fillFaint,
),
controller: _verificationCodeController,
autofocus: false,
autocorrect: false,
keyboardType: TextInputType.number,
onChanged: (_) {
setState(() {});
},
2020-12-12 00:31:06 +00:00
),
),
Divider(
2022-06-19 10:04:53 +00:00
thickness: 1,
color: getEnteColorScheme(context).strokeFaint,
),
Padding(
padding: const EdgeInsets.all(20),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {
UserService.instance.sendOtt(
2022-06-11 08:23:52 +00:00
context,
widget.email,
isCreateAccountScreen: widget.isCreateAccountScreen,
2023-07-18 12:05:30 +00:00
isResetPasswordScreen: widget.isResetPasswordScreen,
isChangeEmail: widget.isChangeEmail,
2022-06-11 08:23:52 +00:00
);
},
2022-06-02 05:02:37 +00:00
child: Text(
S.of(context).resendEmail,
2023-06-13 06:41:31 +00:00
style: Theme.of(context).textTheme.titleMedium!.copyWith(
2022-06-11 08:23:52 +00:00
fontSize: 14,
decoration: TextDecoration.underline,
),
2022-06-02 05:02:37 +00:00
),
2023-08-19 11:39:56 +00:00
),
],
),
),
],
),
],
2020-08-25 05:51:56 +00:00
);
// );
2020-08-25 05:51:56 +00:00
}
}