view.dart 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/resource/assets.gen.dart';
  3. import 'package:electronic_assistant/resource/colors.gen.dart';
  4. import 'package:electronic_assistant/utils/expand.dart';
  5. import 'package:electronic_assistant/widget/login_code_btn.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter/services.dart';
  8. import 'package:flutter_screenutil/flutter_screenutil.dart';
  9. import 'package:get/get.dart';
  10. import 'controller.dart';
  11. class LoginPage extends BasePage<LoginController> {
  12. const LoginPage({super.key});
  13. @override
  14. bool immersive() {
  15. return true;
  16. }
  17. // 点击空白处收起键盘
  18. @override
  19. void backgroundOnTapEvent() {
  20. super.backgroundOnTapEvent();
  21. FocusScope.of(Get.context!).requestFocus(FocusNode());
  22. }
  23. @override
  24. Widget buildBody(BuildContext context) {
  25. return Stack(
  26. children: [
  27. _buildBackgroundImage(),
  28. Scaffold(
  29. resizeToAvoidBottomInset: false,
  30. backgroundColor: Colors.transparent,
  31. appBar: AppBar(
  32. leading: IconButton(
  33. icon: const Icon(Icons.arrow_back_ios),
  34. onPressed: () {
  35. Navigator.pop(context);
  36. },
  37. ),
  38. backgroundColor: Colors.transparent,
  39. systemOverlayStyle: SystemUiOverlayStyle.dark,
  40. ),
  41. body: Column(
  42. crossAxisAlignment: CrossAxisAlignment.start,
  43. children: [
  44. Container(
  45. margin: EdgeInsets.only(left: 28.w, top: 64.h),
  46. width: 194.w,
  47. height: 71.h,
  48. child: Image(image: Assets.images.iconLoginLogo.provider()),
  49. ),
  50. _buildPhoneTextField(),
  51. _buildCodeTextField(),
  52. _buildLoginBtn(),
  53. _buildAgreeText(),
  54. ],
  55. ),
  56. ),
  57. ],
  58. );
  59. // return Scaffold(
  60. // body: Column(
  61. // children: <Widget>[
  62. // TextField(
  63. // onChanged: (text) {
  64. // controller.setPhone(text);
  65. // },
  66. // decoration: const InputDecoration(
  67. // labelText: "手机号",
  68. // hintText: "您的手机号",
  69. // prefixIcon: Icon(Icons.person)),
  70. // ),
  71. // TextField(
  72. // onChanged: (text) {
  73. // controller.setCode(text);
  74. // },
  75. // decoration: const InputDecoration(
  76. // labelText: "验证码",
  77. // hintText: "您的验证码",
  78. // prefixIcon: Icon(Icons.lock)),
  79. // ),
  80. // ElevatedButton(
  81. // child: const Text("获取验证码"),
  82. // onPressed: () {
  83. // controller.getUserCode();
  84. // },
  85. // ),
  86. // ElevatedButton(
  87. // child: const Text("登录"),
  88. // onPressed: () {
  89. // controller.login();
  90. // },
  91. // )
  92. // ],
  93. // ),
  94. // );
  95. }
  96. // 背景图片
  97. Widget _buildBackgroundImage() {
  98. return Image(image: Assets.images.bgLogin.provider());
  99. }
  100. // 电话号码输入框
  101. Widget _buildPhoneTextField() {
  102. return Container(
  103. margin: EdgeInsets.only(top: 44.h, left: 28.w, right: 28.w),
  104. alignment: Alignment.center,
  105. height: 44.h,
  106. decoration: BoxDecoration(
  107. border: Border(
  108. bottom: BorderSide(
  109. width: 1.0,
  110. color: "#F0F0F0".toColor(),
  111. ),
  112. ),
  113. ),
  114. child: TextField(
  115. maxLines: 1,
  116. textAlignVertical: TextAlignVertical.center,
  117. textInputAction: TextInputAction.search,
  118. decoration: InputDecoration(
  119. hintText: '输入手机号码',
  120. hintStyle: TextStyle(fontSize: 16, color: "#AFAFAF".toColor()),
  121. labelStyle: const TextStyle(
  122. fontSize: 16,
  123. color: ColorName.primaryTextColor,
  124. ),
  125. contentPadding: const EdgeInsets.all(0),
  126. border: const OutlineInputBorder(borderSide: BorderSide.none),
  127. enabled: true,
  128. ),
  129. style: TextStyle(fontSize: 14.sp),
  130. onChanged: (value) {
  131. controller.setPhone(value);
  132. },
  133. ),
  134. );
  135. }
  136. // 验证码输入框
  137. Widget _buildCodeTextField() {
  138. return Container(
  139. margin: EdgeInsets.only(top: 36.h, left: 28.w, right: 28.w),
  140. alignment: Alignment.center,
  141. height: 44.h,
  142. decoration: BoxDecoration(
  143. border: Border(
  144. bottom: BorderSide(
  145. width: 1.0,
  146. color: "#F0F0F0".toColor(),
  147. ),
  148. ),
  149. ),
  150. child: Row(
  151. children: [
  152. Expanded(
  153. child: TextField(
  154. maxLines: 1,
  155. textAlignVertical: TextAlignVertical.center,
  156. textInputAction: TextInputAction.search,
  157. decoration: InputDecoration(
  158. hintText: '输入验证码',
  159. hintStyle: TextStyle(fontSize: 16, color: "#AFAFAF".toColor()),
  160. labelStyle: const TextStyle(
  161. fontSize: 16,
  162. color: ColorName.primaryTextColor,
  163. ),
  164. contentPadding: const EdgeInsets.all(0),
  165. border: const OutlineInputBorder(borderSide: BorderSide.none),
  166. enabled: true,
  167. ),
  168. style: TextStyle(fontSize: 14.sp),
  169. onChanged: (value) {
  170. controller.setCode(value);
  171. },
  172. ),
  173. ),
  174. LoginCodeBtn(
  175. onTapCallback: () {
  176. controller.getUserCode();
  177. },
  178. available: true,
  179. ),
  180. ],
  181. ),
  182. );
  183. }
  184. // 登录按钮
  185. Widget _buildLoginBtn() {
  186. return GestureDetector(
  187. onTap: () {
  188. controller.login();
  189. },
  190. child: Container(
  191. margin: EdgeInsets.only(
  192. top: 54.h,
  193. left: 28.w,
  194. right: 28.w,
  195. ),
  196. height: 48.h,
  197. alignment: Alignment.center,
  198. decoration: BoxDecoration(
  199. gradient: LinearGradient(
  200. colors: ['#6177F2'.toColor(), '#8B9DFF'.toColor()],
  201. stops: const [0, 1.0],
  202. ),
  203. borderRadius: BorderRadius.circular(8),
  204. ),
  205. child: const Text(
  206. "登录",
  207. style: TextStyle(
  208. color: ColorName.white,
  209. fontSize: 16,
  210. fontWeight: FontWeight.w500,
  211. ),
  212. ),
  213. ),
  214. );
  215. }
  216. Widget _buildAgreeText() {
  217. return Container(
  218. margin: EdgeInsets.only(left: 28.w, top: 16.h),
  219. child: Row(
  220. children: [
  221. Obx(
  222. () {
  223. return GestureDetector(
  224. onTap: () {
  225. controller.isAgree.value = !controller.isAgree.value;
  226. },
  227. child: SizedBox(
  228. width: 20.w,
  229. height: 20.w,
  230. child: controller.isAgree.value
  231. ? Assets.images.iconSelectTrue.image()
  232. : Assets.images.iconSelectFalse.image()),
  233. );
  234. },
  235. ),
  236. Text(
  237. "我已阅读并同意",
  238. style: TextStyle(
  239. color: "#AFAFAF".toColor(),
  240. fontSize: 12,
  241. ),
  242. ),
  243. GestureDetector(
  244. onTap: () {},
  245. child: Text(
  246. "《隐私政策》",
  247. style: TextStyle(
  248. color: "#5E8BFF".toColor(),
  249. fontSize: 12,
  250. ),
  251. ),
  252. ),
  253. Text(
  254. "和",
  255. style: TextStyle(
  256. color: "#AFAFAF".toColor(),
  257. fontSize: 12,
  258. ),
  259. ),
  260. GestureDetector(
  261. onTap: () {},
  262. child: Text(
  263. "《用户使用协议》",
  264. style: TextStyle(
  265. color: "#5E8BFF".toColor(),
  266. fontSize: 12,
  267. ),
  268. ),
  269. ),
  270. ],
  271. ),
  272. );
  273. }
  274. }