ente/lib/ui/account/change_email_dialog.dart

82 lines
2.3 KiB
Dart
Raw Normal View History

2021-07-28 18:06:30 +00:00
import 'package:flutter/material.dart';
2023-03-21 03:28:13 +00:00
import "package:photos/generated/l10n.dart";
2021-07-28 18:06:30 +00:00
import 'package:photos/services/user_service.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/email_util.dart';
class ChangeEmailDialog extends StatefulWidget {
const ChangeEmailDialog({Key? key}) : super(key: key);
2021-07-28 18:06:30 +00:00
@override
2022-07-03 09:45:00 +00:00
State<ChangeEmailDialog> createState() => _ChangeEmailDialogState();
2021-07-28 18:06:30 +00:00
}
class _ChangeEmailDialogState extends State<ChangeEmailDialog> {
String? _email;
2021-07-28 18:06:30 +00:00
@override
Widget build(BuildContext context) {
return AlertDialog(
2023-03-21 03:28:13 +00:00
title: Text(S.of(context).enterYourEmailAddress),
2021-07-28 18:06:30 +00:00
content: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
2022-07-04 06:02:17 +00:00
decoration: const InputDecoration(
2023-03-25 01:37:01 +00:00
hintText: S.of(context).email,
2021-07-28 18:06:30 +00:00
hintStyle: TextStyle(
color: Colors.white30,
),
contentPadding: EdgeInsets.all(12),
),
onChanged: (value) {
setState(() {
_email = value;
});
},
autocorrect: false,
keyboardType: TextInputType.emailAddress,
initialValue: _email,
autofocus: true,
),
],
),
),
actions: [
TextButton(
2022-07-04 06:02:17 +00:00
child: const Text(
2023-03-25 01:37:01 +00:00
S.of(context).cancel,
2021-07-28 18:06:30 +00:00
style: TextStyle(
color: Colors.redAccent,
),
),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
2022-07-04 06:02:17 +00:00
child: const Text(
2023-03-25 01:37:01 +00:00
S.of(context).verify,
2021-07-28 18:06:30 +00:00
style: TextStyle(
2022-05-16 20:38:11 +00:00
color: Colors.green,
2021-07-28 18:06:30 +00:00
),
),
onPressed: () {
if (!isValidEmail(_email)) {
2022-06-11 08:23:52 +00:00
showErrorDialog(
context,
2023-03-25 01:37:01 +00:00
S.of(context).invalidEmailAddress,
2022-06-11 08:23:52 +00:00
"Please enter a valid email address.",
);
2021-07-28 18:06:30 +00:00
return;
}
2022-12-30 10:03:50 +00:00
UserService.instance.sendOtt(context, _email!, isChangeEmail: true);
2021-07-28 18:06:30 +00:00
},
),
],
);
}
}