view.dart 7.6 KB

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