123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 Container(
  108. width: 250,
  109. height: 250,
  110. decoration: const BoxDecoration(
  111. image: DecorationImage(
  112. image: AssetImage("images/icon_login.png"),
  113. fit: BoxFit.cover,
  114. ),
  115. ),
  116. child: Scaffold(
  117. backgroundColor: Colors.transparent, //把scaffold的背景色改成透明
  118. body: Center(
  119. child: Column(
  120. mainAxisAlignment: MainAxisAlignment.end,
  121. crossAxisAlignment: CrossAxisAlignment.start,
  122. children:[
  123. const Text(
  124. '您好!',
  125. style: TextStyle(
  126. fontWeight: FontWeight.bold,
  127. fontSize: 50,
  128. ),
  129. ),
  130. const Text(
  131. '欢迎进入农户端应用!',
  132. style: TextStyle(
  133. fontWeight: FontWeight.bold,
  134. fontSize: 35,
  135. ),
  136. ),
  137. Cell(
  138. // margin: EdgeInsets.symmetric(horizontal: 13.w),
  139. margin: const EdgeInsets.fromLTRB(13, 43, 10, 0),
  140. header: Text(
  141. "+86",
  142. style: TextStyle(
  143. fontSize: 19.sp,
  144. ),
  145. ),
  146. child: TextField(
  147. maxLength: 11,
  148. keyboardType: TextInputType.number,
  149. style: TextStyle(
  150. fontSize: 17.sp,
  151. ),
  152. decoration: const InputDecoration(
  153. isCollapsed: true,
  154. contentPadding:
  155. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  156. labelText: "请输入手机号码",
  157. counterText: '', //去掉计数
  158. border: InputBorder.none,
  159. floatingLabelBehavior: FloatingLabelBehavior.never,
  160. ),
  161. onChanged: (e) {
  162. _handlePhone(e);
  163. },
  164. ),
  165. footer: SizedBox(
  166. width: 300.w,
  167. child: ElevatedButton(
  168. onPressed: () => {
  169. setState(() {
  170. // _buttonClickListen();
  171. setState(() {
  172. if (isButtonEnable) {
  173. if (handlePhones != '') {
  174. isButtonEnable = false; //按钮状态标记
  175. _initTimer();
  176. getSMSCaptch(handlePhones);
  177. } else {
  178. Fluttertoast.showToast(msg: '请正确输入手机号!');
  179. }
  180. print('获取验证码按钮222222');
  181. }
  182. });
  183. })
  184. },
  185. child: Text(
  186. '$buttonText',
  187. style: TextStyle(
  188. fontSize: 15.sp,
  189. ),
  190. ),
  191. style: ButtonStyle(
  192. backgroundColor: isButtonEnable
  193. ? MaterialStateProperty.all(const Color(0xFFFF703B))
  194. : MaterialStateProperty.all(
  195. const Color(0xFFCBCBCB)),
  196. shape: MaterialStateProperty.all(
  197. const RoundedRectangleBorder(
  198. borderRadius:
  199. BorderRadius.all(Radius.circular(10)))),
  200. ),
  201. ),
  202. )),
  203. // --------------FractionalOffset API--------------
  204. Cell(
  205. // margin: EdgeInsets.symmetric(horizontal: 13.w),
  206. margin: const EdgeInsets.fromLTRB(13, 16, 10, 0),
  207. header: Align(
  208. alignment: FractionalOffset(0.1, 0.5),
  209. child: Image.asset(
  210. 'images/phoneCode.png',
  211. width: 20,
  212. height: 20,
  213. ),
  214. ),
  215. child: TextField(
  216. keyboardType: TextInputType.number,
  217. style: TextStyle(
  218. fontSize: 17.sp,
  219. ),
  220. decoration: const InputDecoration(
  221. isCollapsed: true,
  222. contentPadding:
  223. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  224. labelText: "请输入验证码",
  225. border: InputBorder.none,
  226. floatingLabelBehavior: FloatingLabelBehavior.never,
  227. ),
  228. onChanged: (e) {
  229. _handleCode(e);
  230. },
  231. ),
  232. ),
  233. Container(
  234. height: 350.h,
  235. alignment: Alignment.bottomCenter,
  236. child: SizedBox(
  237. width: 315.w,
  238. height: 49.h,
  239. child: ElevatedButton(
  240. onPressed: () {
  241. if(handleCodes==''||handlePhones==''){
  242. Fluttertoast.showToast(msg: '请输入验证码或手机号!');
  243. }else{
  244. if(_newValue){
  245. print('已同意协议');
  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. backgroundColor:
  260. MaterialStateProperty.all(const Color(0xFFFF703B)),
  261. shape: MaterialStateProperty.all(
  262. const RoundedRectangleBorder(
  263. borderRadius:
  264. BorderRadius.all(Radius.circular(24.4)))),
  265. ),
  266. ),
  267. ),
  268. ),
  269. Padding(
  270. padding: EdgeInsets.fromLTRB(10.0, 10, 10.0, 10),
  271. child: Row(
  272. children: <Widget>[
  273. Radio<bool>(
  274. value: true,
  275. activeColor: Color(0xFFFF703B),
  276. groupValue: _newValue,
  277. onChanged: (value) {
  278. setState(() {
  279. _newValue = value!;
  280. });
  281. }),
  282. RichText(
  283. text: TextSpan(children: <InlineSpan>[
  284. TextSpan(
  285. text: '请认真查看',
  286. style: TextStyle(color: Color(0xff2a2a2a))),
  287. TextSpan(
  288. text: '文本协议/隐私政策,',
  289. style: TextStyle(color: Color(0xffce3800)),
  290. recognizer:
  291. TapGestureRecognizer() //踩坑。。。recognizer 是手势交互 除了我现在些的是 点击交互,其他一般都是抽象类。
  292. ..onTap = () {
  293. print('阅读已同意!!!');
  294. },
  295. ),
  296. TextSpan(
  297. text: '确认之后选择此项',
  298. style: TextStyle(color: Color(0xff2a2a2a))),
  299. ]),
  300. ),
  301. ],
  302. )),
  303. ],
  304. ),
  305. ),
  306. ),
  307. );
  308. }
  309. }