email_entry_page.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:photos/core/configuration.dart';
  5. import 'package:photos/services/user_service.dart';
  6. import 'package:photos/ui/common_elements.dart';
  7. import 'package:photos/utils/dialog_util.dart';
  8. import 'package:photos/utils/email_util.dart';
  9. class EmailEntryPage extends StatefulWidget {
  10. EmailEntryPage({Key key}) : super(key: key);
  11. @override
  12. _EmailEntryPageState createState() => _EmailEntryPageState();
  13. }
  14. class _EmailEntryPageState extends State<EmailEntryPage> {
  15. final _config = Configuration.instance;
  16. String _email;
  17. String _name;
  18. @override
  19. void initState() {
  20. _email = _config.getEmail();
  21. _name = _config.getName();
  22. super.initState();
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return Scaffold(
  27. appBar: AppBar(
  28. title: Text("Sign Up"),
  29. ),
  30. body: _getBody(),
  31. );
  32. }
  33. Widget _getBody() {
  34. return SingleChildScrollView(
  35. child: Container(
  36. padding: EdgeInsets.all(8),
  37. child: Column(
  38. children: [
  39. Image.asset(
  40. "assets/welcome.png",
  41. width: 300,
  42. height: 200,
  43. ),
  44. Padding(padding: EdgeInsets.all(12)),
  45. TextFormField(
  46. decoration: InputDecoration(
  47. hintText: 'your name',
  48. contentPadding: EdgeInsets.all(12),
  49. ),
  50. onChanged: (value) {
  51. setState(() {
  52. _name = value;
  53. });
  54. },
  55. autofocus: true,
  56. autocorrect: false,
  57. keyboardType: TextInputType.text,
  58. textCapitalization: TextCapitalization.words,
  59. initialValue: _name,
  60. ),
  61. Padding(padding: EdgeInsets.all(8)),
  62. TextFormField(
  63. decoration: InputDecoration(
  64. hintText: 'you@email.com',
  65. contentPadding: EdgeInsets.all(12),
  66. ),
  67. onChanged: (value) {
  68. setState(() {
  69. _email = value;
  70. });
  71. },
  72. autocorrect: false,
  73. keyboardType: TextInputType.emailAddress,
  74. initialValue: _email,
  75. ),
  76. Padding(padding: EdgeInsets.all(12)),
  77. Container(
  78. width: double.infinity,
  79. height: 44,
  80. child: button("Sign In", onPressed: () {
  81. if (!isValidEmail(_email)) {
  82. showErrorDialog(context, "Invalid email address",
  83. "Please enter a valid email address.");
  84. return;
  85. }
  86. _config.setEmail(_email);
  87. _config.setName(_name);
  88. UserService.instance.getOtt(context, _email);
  89. }),
  90. ),
  91. ],
  92. ),
  93. ),
  94. );
  95. }
  96. }