login.dart 11KB

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