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