ott_verification_page.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/services/user_service.dart';
  4. import 'package:photos/ui/common/dynamicFAB.dart';
  5. import 'package:step_progress_indicator/step_progress_indicator.dart';
  6. class OTTVerificationPage extends StatefulWidget {
  7. final String email;
  8. final bool isChangeEmail;
  9. final bool isCreateAccountScreen;
  10. OTTVerificationPage(
  11. this.email, {
  12. this.isChangeEmail = false,
  13. this.isCreateAccountScreen,
  14. Key key,
  15. }) : super(key: key);
  16. @override
  17. _OTTVerificationPageState createState() => _OTTVerificationPageState();
  18. }
  19. class _OTTVerificationPageState extends State<OTTVerificationPage> {
  20. final _verificationCodeController = TextEditingController();
  21. @override
  22. Widget build(BuildContext context) {
  23. final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom != 0;
  24. FloatingActionButtonLocation fabLocation() {
  25. if (isKeypadOpen) {
  26. return null;
  27. } else {
  28. return FloatingActionButtonLocation.centerFloat;
  29. }
  30. }
  31. return Scaffold(
  32. appBar: AppBar(
  33. elevation: 0,
  34. leading: IconButton(
  35. icon: Icon(Icons.arrow_back),
  36. color: Theme.of(context).iconTheme.color,
  37. onPressed: () {
  38. Navigator.of(context).pop();
  39. },
  40. ),
  41. title: widget.isCreateAccountScreen
  42. ? Hero(
  43. tag: "sign_up",
  44. child: Material(
  45. type: MaterialType.transparency,
  46. child: StepProgressIndicator(
  47. totalSteps: 4,
  48. currentStep: 1,
  49. selectedColor: Theme.of(context).buttonColor,
  50. roundedEdges: Radius.circular(10),
  51. unselectedColor: Theme.of(context).bottomAppBarColor,
  52. )),
  53. )
  54. : null,
  55. ),
  56. body: _getBody(),
  57. floatingActionButton: DynamicFAB(
  58. isKeypadOpen: isKeypadOpen,
  59. isFormValid: !(_verificationCodeController.text == null ||
  60. _verificationCodeController.text.isEmpty),
  61. buttonText: 'Verify',
  62. onPressedFunction: () {
  63. if (widget.isChangeEmail) {
  64. UserService.instance.changeEmail(
  65. context, widget.email, _verificationCodeController.text);
  66. } else {
  67. UserService.instance
  68. .verifyEmail(context, _verificationCodeController.text);
  69. }
  70. },
  71. ),
  72. floatingActionButtonLocation: fabLocation(),
  73. );
  74. }
  75. Widget _getBody() {
  76. //return SingleChildScrollView(
  77. //child:
  78. return ListView(
  79. children: [
  80. Column(
  81. crossAxisAlignment: CrossAxisAlignment.start,
  82. children: [
  83. Padding(
  84. padding: const EdgeInsets.fromLTRB(20, 30, 20, 15),
  85. child: Text('Verify email',
  86. style: Theme.of(context).textTheme.headline4),
  87. ),
  88. // Text(
  89. // "We've sent a mail to " + widget.email,
  90. // style: TextStyle(
  91. // color: Theme.of(context).buttonColor,
  92. // fontSize: 18,
  93. // ),
  94. // ),
  95. Padding(
  96. padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
  97. child: Row(
  98. children: [
  99. Expanded(
  100. child: Column(
  101. crossAxisAlignment: CrossAxisAlignment.start,
  102. children: [
  103. Padding(
  104. padding: const EdgeInsets.fromLTRB(0, 0, 0, 5),
  105. child: RichText(
  106. text: TextSpan(
  107. style: Theme.of(context)
  108. .textTheme
  109. .subtitle1
  110. .copyWith(fontSize: 12),
  111. children: [
  112. TextSpan(text: "We've sent a mail to "),
  113. TextSpan(
  114. text: widget.email,
  115. style: TextStyle(
  116. color: Theme.of(context).buttonColor))
  117. ],
  118. ),
  119. ),
  120. ),
  121. Text(
  122. 'Please check your inbox (and spam) to complete verification',
  123. style: Theme.of(context)
  124. .textTheme
  125. .subtitle1
  126. .copyWith(fontSize: 12),
  127. ),
  128. ],
  129. ),
  130. ),
  131. SizedBox(
  132. width: MediaQuery.of(context).size.width * 0.3,
  133. height: 1,
  134. )
  135. ],
  136. ),
  137. ),
  138. // Padding(
  139. // padding: const EdgeInsets.all(32),
  140. // child: Text(
  141. // "please check your inbox (and spam) to complete verification.",
  142. // textAlign: TextAlign.center,
  143. // style: TextStyle(fontSize: 12),
  144. // ),
  145. // ),
  146. Padding(
  147. padding: const EdgeInsets.fromLTRB(20, 10, 20, 15),
  148. child: TextFormField(
  149. style: Theme.of(context).textTheme.subtitle1,
  150. decoration: InputDecoration(
  151. filled: true,
  152. hintText: 'tap to enter code',
  153. contentPadding: EdgeInsets.all(15),
  154. border: UnderlineInputBorder(
  155. borderSide: BorderSide.none,
  156. borderRadius: BorderRadius.circular(6)),
  157. ),
  158. controller: _verificationCodeController,
  159. autofocus: false,
  160. autocorrect: false,
  161. keyboardType: TextInputType.visiblePassword,
  162. onChanged: (_) {
  163. setState(() {});
  164. },
  165. ),
  166. ),
  167. Divider(
  168. thickness: 1.5,
  169. ),
  170. Padding(
  171. padding: const EdgeInsets.all(20),
  172. child: Row(
  173. mainAxisAlignment: MainAxisAlignment.end,
  174. children: [
  175. TextButton(
  176. onPressed: () {
  177. //Navigator.of(context).pop();
  178. UserService.instance.getOtt(context, widget.email,
  179. isCreateAccountScreen: widget.isCreateAccountScreen);
  180. },
  181. child: Text("Resend email",
  182. style: Theme.of(context).textTheme.subtitle1.copyWith(
  183. fontSize: 14,
  184. decoration: TextDecoration
  185. .underline) //hardcoded //is this okay? //functionality not added
  186. ),
  187. )
  188. ],
  189. ),
  190. ),
  191. ],
  192. ),
  193. ],
  194. );
  195. // );
  196. }
  197. }