view.dart 7.5 KB

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