ente/lib/ui/account/ott_verification_page.dart

202 lines
6.7 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';
2020-10-03 17:56:18 +00:00
import 'package:photos/services/user_service.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';
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;
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,
2021-07-28 18:06:30 +00:00
Key key,
}) : 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,
selectedColor: Theme.of(context).buttonColor,
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(
isKeypadOpen: isKeypadOpen,
isFormValid: !(_verificationCodeController.text == null ||
_verificationCodeController.text.isEmpty),
buttonText: '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);
}
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(
'Verify email',
style: Theme.of(context).textTheme.headline4,
),
),
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),
child: RichText(
2022-05-03 11:53:18 +00:00
text: TextSpan(
style: Theme.of(context)
.textTheme
.subtitle1
2022-06-19 10:04:53 +00:00
.copyWith(fontSize: 14),
2022-05-03 11:53:18 +00:00
children: [
2022-07-04 06:02:17 +00:00
const TextSpan(text: "We've sent a mail to "),
TextSpan(
2022-06-11 08:23:52 +00:00
text: widget.email,
style: TextStyle(
color: Theme.of(context).buttonColor,
),
)
2022-05-03 11:53:18 +00:00
],
),
),
),
Text(
'Please check your inbox (and spam) to complete verification',
style: Theme.of(context)
.textTheme
.subtitle1
2022-06-19 10:04:53 +00:00
.copyWith(fontSize: 14),
),
],
),
),
SizedBox(
2022-06-19 10:04:53 +00:00
width: MediaQuery.of(context).size.width * 0.2,
height: 1,
)
],
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(
style: Theme.of(context).textTheme.subtitle1,
decoration: InputDecoration(
filled: true,
2022-05-30 14:13:19 +00:00
hintText: 'Tap to enter code',
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),
),
),
controller: _verificationCodeController,
autofocus: false,
autocorrect: false,
keyboardType: TextInputType.number,
onChanged: (_) {
setState(() {});
},
2020-12-12 00:31:06 +00:00
),
),
2022-07-04 06:02:17 +00:00
const Divider(
2022-06-19 10:04:53 +00:00
thickness: 1,
),
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,
);
},
2022-06-02 05:02:37 +00:00
child: Text(
"Resend email",
style: Theme.of(context).textTheme.subtitle1.copyWith(
2022-06-11 08:23:52 +00:00
fontSize: 14,
decoration: TextDecoration.underline,
),
2022-06-02 05:02:37 +00:00
),
)
],
),
),
],
),
],
2020-08-25 05:51:56 +00:00
);
// );
2020-08-25 05:51:56 +00:00
}
}