login.dart 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import 'dart:async';
  2. import 'dart:ffi';
  3. import 'package:fluttertoast/fluttertoast.dart';
  4. import 'package:flutter/gestures.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import '../../services/user.dart';
  8. import '../../widgets/Cell.dart';
  9. class MyRouteLogin extends StatefulWidget {
  10. @override
  11. State<MyRouteLogin> createState() => _RouteLogin();
  12. }
  13. class _RouteLogin extends State<MyRouteLogin> {
  14. @override
  15. void initState() {
  16. super.initState();
  17. //注册协议的手势
  18. }
  19. bool isButtonEnable = true; //按钮状态 是否可点击
  20. String buttonText = '发送验证码'; //初始文本
  21. int count = 60; //初始倒计时时间
  22. var timer; //倒计时的计时器
  23. TextEditingController mController = TextEditingController();
  24. void _initTimer() {
  25. timer = Timer.periodic(Duration(seconds: 1), (Timer timer) {
  26. count--;
  27. setState(() {
  28. if (count == 0) {
  29. timer.cancel(); //倒计时结束取消定时器
  30. isButtonEnable = true; //按钮可点击
  31. count = 60; //重置时间
  32. buttonText = '发送验证码'; //重置按钮文本
  33. } else {
  34. buttonText = '重新发送($count)'; //更新文本内容
  35. }
  36. });
  37. });
  38. }
  39. @override
  40. void dispose() {
  41. timer?.cancel(); //销毁计时器
  42. timer = null;
  43. mController.dispose();
  44. super.dispose();
  45. ///销毁
  46. }
  47. // -------------逻辑分割-------------------------------------------
  48. var handlePhones = '';
  49. var handleCodes = '';
  50. void _handlePhone(e) => {
  51. setState(() => {handlePhones = e})
  52. };
  53. void _handleCode(e) => {
  54. setState(() => {handleCodes = e})
  55. };
  56. var userContent = {'phones': '', 'code': ''};
  57. void phoneUser() => {
  58. setState(() {
  59. userContent['phones'] = handlePhones;
  60. userContent['code'] = handleCodes;
  61. }),
  62. print('我输入的信息:${userContent},手机号:${userContent['phones']}')
  63. };
  64. bool _checkValue = false;
  65. bool _newValue = false;
  66. void _buttonClickListen() {
  67. setState(() {
  68. if (isButtonEnable) {
  69. if (handlePhones != '') {
  70. isButtonEnable = false; //按钮状态标记
  71. _initTimer();
  72. getSMSCaptch(handlePhones);
  73. } else {
  74. Fluttertoast.showToast(msg: '请正确输入手机号!');
  75. }
  76. print('获取验证码按钮222222');
  77. }
  78. });
  79. }
  80. @override
  81. Widget build(BuildContext context) {
  82. return Container(
  83. width: 250,
  84. height: 250,
  85. decoration: const BoxDecoration(
  86. image: DecorationImage(
  87. image: AssetImage("images/icon_login.png"),
  88. fit: BoxFit.cover,
  89. ),
  90. ),
  91. child: Scaffold(
  92. backgroundColor: Colors.transparent, //把scaffold的背景色改成透明
  93. body: Center(
  94. child: Column(
  95. mainAxisAlignment: MainAxisAlignment.end,
  96. crossAxisAlignment: CrossAxisAlignment.start,
  97. children:[
  98. const Text(
  99. '您好!',
  100. style: TextStyle(
  101. fontWeight: FontWeight.bold,
  102. fontSize: 50,
  103. ),
  104. ),
  105. const Text(
  106. '欢迎进入农户端应用!',
  107. style: TextStyle(
  108. fontWeight: FontWeight.bold,
  109. fontSize: 35,
  110. ),
  111. ),
  112. Cell(
  113. // margin: EdgeInsets.symmetric(horizontal: 13.w),
  114. margin: const EdgeInsets.fromLTRB(13, 43, 10, 0),
  115. header: Text(
  116. "+86",
  117. style: TextStyle(
  118. fontSize: 19.sp,
  119. ),
  120. ),
  121. child: TextField(
  122. maxLength: 11,
  123. keyboardType: TextInputType.number,
  124. style: TextStyle(
  125. fontSize: 17.sp,
  126. ),
  127. decoration: const InputDecoration(
  128. isCollapsed: true,
  129. contentPadding:
  130. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  131. labelText: "请输入手机号码",
  132. counterText: '', //去掉计数
  133. border: InputBorder.none,
  134. floatingLabelBehavior: FloatingLabelBehavior.never,
  135. ),
  136. onChanged: (e) {
  137. _handlePhone(e);
  138. },
  139. ),
  140. footer: SizedBox(
  141. width: 300.w,
  142. child: ElevatedButton(
  143. onPressed: () => {
  144. setState(() {
  145. // _buttonClickListen();
  146. setState(() {
  147. if (isButtonEnable) {
  148. if (handlePhones != '') {
  149. isButtonEnable = false; //按钮状态标记
  150. _initTimer();
  151. getSMSCaptch(handlePhones);
  152. } else {
  153. Fluttertoast.showToast(msg: '请正确输入手机号!');
  154. }
  155. print('获取验证码按钮222222');
  156. }
  157. });
  158. })
  159. },
  160. child: Text(
  161. '$buttonText',
  162. style: TextStyle(
  163. fontSize: 15.sp,
  164. ),
  165. ),
  166. style: ButtonStyle(
  167. backgroundColor: isButtonEnable
  168. ? MaterialStateProperty.all(const Color(0xFFFF703B))
  169. : MaterialStateProperty.all(
  170. const Color(0xFFCBCBCB)),
  171. shape: MaterialStateProperty.all(
  172. const RoundedRectangleBorder(
  173. borderRadius:
  174. BorderRadius.all(Radius.circular(10)))),
  175. ),
  176. ),
  177. )),
  178. // --------------FractionalOffset API--------------
  179. Cell(
  180. // margin: EdgeInsets.symmetric(horizontal: 13.w),
  181. margin: const EdgeInsets.fromLTRB(13, 16, 10, 0),
  182. header: Align(
  183. alignment: FractionalOffset(0.1, 0.5),
  184. child: Image.asset(
  185. 'images/phoneCode.png',
  186. width: 20,
  187. height: 20,
  188. ),
  189. ),
  190. child: TextField(
  191. keyboardType: TextInputType.number,
  192. style: TextStyle(
  193. fontSize: 17.sp,
  194. ),
  195. decoration: const InputDecoration(
  196. isCollapsed: true,
  197. contentPadding:
  198. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  199. labelText: "请输入验证码",
  200. border: InputBorder.none,
  201. floatingLabelBehavior: FloatingLabelBehavior.never,
  202. ),
  203. onChanged: (e) {
  204. _handleCode(e);
  205. },
  206. ),
  207. ),
  208. Container(
  209. height: 350.h,
  210. alignment: Alignment.bottomCenter,
  211. child: SizedBox(
  212. width: 315.w,
  213. height: 49.h,
  214. child: ElevatedButton(
  215. onPressed: () {
  216. if(handleCodes==''||handlePhones==''){
  217. Fluttertoast.showToast(msg: '请输入验证码或手机号!');
  218. }else{
  219. if(_newValue){
  220. print('已同意协议');
  221. }else{
  222. Fluttertoast.showToast(msg: '请阅读并同意相关隐私政策!');
  223. }
  224. }
  225. },
  226. child: const Text(
  227. "登陆",
  228. style: TextStyle(
  229. fontSize: 18,
  230. color: Colors.white,
  231. fontWeight: FontWeight.bold),
  232. ),
  233. style: ButtonStyle(
  234. backgroundColor:
  235. MaterialStateProperty.all(const Color(0xFFFF703B)),
  236. shape: MaterialStateProperty.all(
  237. const RoundedRectangleBorder(
  238. borderRadius:
  239. BorderRadius.all(Radius.circular(24.4)))),
  240. ),
  241. ),
  242. ),
  243. ),
  244. Padding(
  245. padding: EdgeInsets.fromLTRB(10.0, 10, 10.0, 10),
  246. child: Row(
  247. children: <Widget>[
  248. Radio<bool>(
  249. value: true,
  250. activeColor: Color(0xFFFF703B),
  251. groupValue: _newValue,
  252. onChanged: (value) {
  253. setState(() {
  254. _newValue = value!;
  255. });
  256. }),
  257. RichText(
  258. text: TextSpan(children: <InlineSpan>[
  259. TextSpan(
  260. text: '请认真查看',
  261. style: TextStyle(color: Color(0xff2a2a2a))),
  262. TextSpan(
  263. text: '文本协议/隐私政策,',
  264. style: TextStyle(color: Color(0xffce3800)),
  265. recognizer:
  266. TapGestureRecognizer() //踩坑。。。recognizer 是手势交互 除了我现在些的是 点击交互,其他一般都是抽象类。
  267. ..onTap = () {
  268. print('阅读已同意!!!');
  269. },
  270. ),
  271. TextSpan(
  272. text: '确认之后选择此项',
  273. style: TextStyle(color: Color(0xff2a2a2a))),
  274. ]),
  275. ),
  276. ],
  277. )),
  278. ],
  279. ),
  280. ),
  281. ),
  282. );
  283. }
  284. }