change_email_dialog.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/services/user_service.dart';
  3. import 'package:photos/utils/dialog_util.dart';
  4. import 'package:photos/utils/email_util.dart';
  5. class ChangeEmailDialog extends StatefulWidget {
  6. const ChangeEmailDialog({Key? key}) : super(key: key);
  7. @override
  8. State<ChangeEmailDialog> createState() => _ChangeEmailDialogState();
  9. }
  10. class _ChangeEmailDialogState extends State<ChangeEmailDialog> {
  11. String? _email;
  12. @override
  13. Widget build(BuildContext context) {
  14. return AlertDialog(
  15. title: const Text("Enter your email address"),
  16. content: SingleChildScrollView(
  17. child: Column(
  18. mainAxisAlignment: MainAxisAlignment.start,
  19. crossAxisAlignment: CrossAxisAlignment.start,
  20. children: [
  21. TextFormField(
  22. decoration: const InputDecoration(
  23. hintText: 'Email',
  24. hintStyle: TextStyle(
  25. color: Colors.white30,
  26. ),
  27. contentPadding: EdgeInsets.all(12),
  28. ),
  29. onChanged: (value) {
  30. setState(() {
  31. _email = value;
  32. });
  33. },
  34. autocorrect: false,
  35. keyboardType: TextInputType.emailAddress,
  36. initialValue: _email,
  37. autofocus: true,
  38. ),
  39. ],
  40. ),
  41. ),
  42. actions: [
  43. TextButton(
  44. child: const Text(
  45. "Cancel",
  46. style: TextStyle(
  47. color: Colors.redAccent,
  48. ),
  49. ),
  50. onPressed: () {
  51. Navigator.pop(context);
  52. },
  53. ),
  54. TextButton(
  55. child: const Text(
  56. "Verify",
  57. style: TextStyle(
  58. color: Colors.green,
  59. ),
  60. ),
  61. onPressed: () {
  62. if (!isValidEmail(_email)) {
  63. showErrorDialog(
  64. context,
  65. "Invalid email address",
  66. "Please enter a valid email address.",
  67. );
  68. return;
  69. }
  70. UserService.instance.sendOtt(context, _email, isChangeEmail: true);
  71. },
  72. ),
  73. ],
  74. );
  75. }
  76. }