Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.10 KB | None | 0 0
  1. import 'package:country_pickers/country.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:shopping_module/bloc/otp_bloc.dart';
  5. import 'package:country_pickers/country_pickers.dart';
  6.  
  7. class OTPLoginSignupScreen extends StatefulWidget {
  8. @override
  9. _OTPLoginSignupScreenState createState() => _OTPLoginSignupScreenState();
  10. }
  11.  
  12. class _OTPLoginSignupScreenState extends State<OTPLoginSignupScreen> {
  13. var errorText;
  14. TextEditingController _textEditingController;
  15. var text = "";
  16. @override
  17. void initState() {
  18. _textEditingController = TextEditingController();
  19. otpBloc.outputStream.listen(_onOTPData);
  20. super.initState();
  21. }
  22.  
  23. @override
  24. void dispose() {
  25. _textEditingController.dispose();
  26. super.dispose();
  27. }
  28.  
  29. @override
  30. void didChangeDependencies() {
  31. print('changed dependencies $text');
  32. super.didChangeDependencies();
  33. }
  34.  
  35. @override
  36. void didUpdateWidget(OTPLoginSignupScreen oldWidget) {
  37. print('did update');
  38. super.didUpdateWidget(oldWidget);
  39. }
  40.  
  41. Widget _buildDropdownItem(Country country) => Container(
  42. child: Row(
  43. children: <Widget>[
  44. // CountryPickerUtils.getDefaultFlagImage(country),
  45. // SizedBox(
  46. // width: 2.0,
  47. // ),
  48. Text("+${country.phoneCode}(${country.isoCode})"),
  49. ],
  50. ),
  51. );
  52.  
  53. @override
  54. Widget build(BuildContext context) {
  55. return Scaffold(
  56. body: GestureDetector(
  57. onTap: () {
  58. FocusScope.of(context).requestFocus(new FocusNode());
  59. },
  60. child: Container(
  61. height: MediaQuery.of(context).size.height,
  62. width: MediaQuery.of(context).size.width,
  63. child: ListView(
  64. children: <Widget>[
  65. SizedBox(
  66. height: 40,
  67. ),
  68. Image.asset(
  69. 'assets/verify.png',
  70. height: ScreenUtil.getInstance().setHeight(900),
  71. fit: BoxFit.fitHeight,
  72. ),
  73. SizedBox(height: 8),
  74. Padding(
  75. padding: const EdgeInsets.symmetric(vertical: 8.0),
  76. child: Text(
  77. 'Phone Number Verification',
  78. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22),
  79. textAlign: TextAlign.center,
  80. ),
  81. ),
  82. Padding(
  83. padding:
  84. const EdgeInsets.symmetric(horizontal: 30.0, vertical: 8),
  85. child: RichText(
  86. text: TextSpan(
  87. text: "We will send you a ",
  88. children: [
  89. TextSpan(
  90. text: "Verification Code ",
  91. style: TextStyle(
  92. color: Colors.black,
  93. fontWeight: FontWeight.bold,
  94. fontSize: 15)),
  95. TextSpan(
  96. text: "on this mobile number",
  97. style:
  98. TextStyle(color: Colors.black54, fontSize: 15)),
  99. ],
  100. style: TextStyle(color: Colors.black54, fontSize: 15)),
  101. textAlign: TextAlign.center,
  102. ),
  103. ),
  104. Padding(
  105. padding:
  106. const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30),
  107. child: StreamBuilder<OutputMap>(
  108. stream: otpBloc.outputStream,
  109. initialData: OutputMap(state: ScreenState.idle, value: ""),
  110. builder: (context, snapshot) {
  111. text = snapshot.data.state.toString();
  112. if (snapshot.hasData) {
  113. if (snapshot.data.state == ScreenState.failed) {
  114. errorText = snapshot.data.value;
  115. } else if (snapshot.data.state ==
  116. ScreenState.codesent) {
  117. // Navigator.pushNamed(context, '/pin_code_verification',
  118. // arguments: _textEditingController.text);
  119. }
  120. print(snapshot.data.state.toString());
  121. return Column(
  122. children: <Widget>[
  123. Text(
  124. 'Enter your phone number',
  125. style: TextStyle(
  126. color: Colors.black54, fontSize: 16),
  127. ),
  128. Row(
  129. children: <Widget>[
  130. Flexible(
  131. flex: 2,
  132. child: CountryPickerDropdown(
  133. initialValue: 'bd',
  134. itemBuilder: _buildDropdownItem,
  135. onValuePicked: (Country country) {
  136. print("${country.name}");
  137. },
  138. ),
  139. ),
  140. Expanded(
  141. flex: 3,
  142. child: TextField(
  143. controller: _textEditingController,
  144. textAlign: TextAlign.left,
  145. style: TextStyle(
  146. fontSize: 18,
  147. color: Colors.black,
  148. fontWeight: FontWeight.bold),
  149. keyboardType: TextInputType.phone,
  150. decoration: InputDecoration(
  151. focusedBorder: UnderlineInputBorder(
  152. borderSide: BorderSide(
  153. width: 1.5,
  154. color: Colors.green)),
  155. // prefix: Text("+88 -"),
  156. // prefixStyle:
  157. // TextStyle(fontSize: 18, color: Colors.black),
  158. hintText: "+8801722114455",
  159. hintStyle: TextStyle(
  160. color: Colors.black26,
  161. fontWeight: FontWeight.w400,
  162. fontStyle: FontStyle.italic),
  163. errorText: errorText),
  164. ),
  165. ),
  166. ],
  167. ),
  168. Container(
  169. margin: const EdgeInsets.symmetric(
  170. vertical: 16.0, horizontal: 30),
  171. child: ButtonTheme(
  172. height: 50,
  173. child: FlatButton(
  174. onPressed: () {
  175. Navigator.pushNamed(
  176. context, "/pin_code_verification",
  177. arguments: _textEditingController.text);
  178. // otpBloc.inputSink.add(InputMap(
  179. // event: Event.verify,
  180. // value: _textEditingController.text));
  181. },
  182. child: Center(
  183. child: (snapshot.data.state !=
  184. ScreenState.idle)
  185. ? SizedBox(
  186. height: 25,
  187. width: 25,
  188. child: CircularProgressIndicator(
  189. backgroundColor:
  190. Colors.green.shade300,
  191. ),
  192. )
  193. : Text(
  194. "Login/Signup".toUpperCase(),
  195. style: TextStyle(
  196. color: Colors.white,
  197. fontSize: 18,
  198. fontWeight: FontWeight.bold),
  199. )),
  200. ),
  201. ),
  202. decoration: BoxDecoration(
  203. color: Colors.green.shade300,
  204. borderRadius: BorderRadius.circular(5),
  205. boxShadow: [
  206. BoxShadow(
  207. color: Colors.green.shade200,
  208. offset: Offset(1, -2),
  209. blurRadius: 5),
  210. BoxShadow(
  211. color: Colors.green.shade200,
  212. offset: Offset(-1, 2),
  213. blurRadius: 5)
  214. ]),
  215. )
  216. ],
  217. );
  218. } else {
  219. return Container();
  220. }
  221. }),
  222. ),
  223. ],
  224. ),
  225. ),
  226. ),
  227. );
  228. }
  229.  
  230. void _onOTPData(OutputMap event) {
  231. if (event.state == ScreenState.timedOut) {
  232. Navigator.pushNamed(context, "/pin_code_verification",
  233. arguments: _textEditingController.text);
  234. } else if (event.state == ScreenState.done) {
  235. Navigator.pushNamed(
  236. context,
  237. "/home",
  238. );
  239. }
  240. }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement