change_email_dialog.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. _ChangeEmailDialogState createState() => _ChangeEmailDialogState();
  9. }
  10. class _ChangeEmailDialogState extends State<ChangeEmailDialog> {
  11. String _email;
  12. @override
  13. Widget build(BuildContext context) {
  14. return AlertDialog(
  15. title: 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: 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: Text(
  45. "Cancel",
  46. style: TextStyle(
  47. color: Colors.redAccent,
  48. ),
  49. ),
  50. onPressed: () {
  51. Navigator.pop(context);
  52. },
  53. ),
  54. TextButton(
  55. child: Text(
  56. "Verify",
  57. style: TextStyle(
  58. color: Colors.green,
  59. ),
  60. ),
  61. onPressed: () {
  62. if (!isValidEmail(_email)) {
  63. showErrorDialog(context, "Invalid email address",
  64. "Please enter a valid email address.");
  65. return;
  66. }
  67. UserService.instance.getOtt(context, _email, isChangeEmail: true);
  68. },
  69. ),
  70. ],
  71. );
  72. }
  73. }