view.dart 7.3 KB

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