view.dart 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. maxLength: 4,
  131. textAlignVertical: TextAlignVertical.center,
  132. textInputAction: TextInputAction.done,
  133. decoration: InputDecoration(
  134. counterText: '',
  135. hintText: '输入验证码',
  136. hintStyle: TextStyle(fontSize: 16, color: "#AFAFAF".toColor()),
  137. labelStyle: const TextStyle(
  138. fontSize: 16,
  139. color: ColorName.primaryTextColor,
  140. ),
  141. contentPadding: const EdgeInsets.all(0),
  142. border: const OutlineInputBorder(borderSide: BorderSide.none),
  143. enabled: true,
  144. ),
  145. style: TextStyle(fontSize: 14.sp),
  146. onChanged: (value) {
  147. controller.setCode(value);
  148. },
  149. ),
  150. ),
  151. LoginCodeBtn(
  152. onTapCallback: () {
  153. controller.getUserCode();
  154. },
  155. available: true,
  156. ),
  157. ],
  158. ),
  159. );
  160. }
  161. // 登录按钮
  162. Widget _buildLoginBtn() {
  163. return GestureDetector(
  164. onTap: () {
  165. controller.login();
  166. },
  167. child: Container(
  168. margin: EdgeInsets.only(
  169. top: 54.h,
  170. left: 28.w,
  171. right: 28.w,
  172. ),
  173. height: 48.h,
  174. alignment: Alignment.center,
  175. decoration: BoxDecoration(
  176. gradient: LinearGradient(
  177. colors: ['#6177F2'.toColor(), '#8B9DFF'.toColor()],
  178. stops: const [0, 1.0],
  179. ),
  180. borderRadius: BorderRadius.circular(8),
  181. ),
  182. child: const Text(
  183. "登录",
  184. style: TextStyle(
  185. color: ColorName.white,
  186. fontSize: 16,
  187. fontWeight: FontWeight.w500,
  188. ),
  189. ),
  190. ),
  191. );
  192. }
  193. Widget _buildAgreeText() {
  194. return Container(
  195. margin: EdgeInsets.only(left: 28.w, top: 16.h),
  196. child: Row(
  197. children: [
  198. Obx(
  199. () {
  200. return GestureDetector(
  201. onTap: () {
  202. controller.isAgree.value = !controller.isAgree.value;
  203. },
  204. child: SizedBox(
  205. width: 20.w,
  206. height: 20.w,
  207. child: controller.isAgree.value
  208. ? Assets.images.iconSelectTrue.image()
  209. : Assets.images.iconSelectFalse.image()),
  210. );
  211. },
  212. ),
  213. Text(
  214. "我已阅读并同意",
  215. style: TextStyle(
  216. color: "#AFAFAF".toColor(),
  217. fontSize: 12,
  218. ),
  219. ),
  220. GestureDetector(
  221. onTap: () {
  222. if (GetPlatform.isIOS) {
  223. BrowserPage.start(Constants.privacyPolicyIos);
  224. } else {
  225. BrowserPage.start(Constants.privacyPolicy);
  226. }
  227. },
  228. child: Text(
  229. "《隐私政策》",
  230. style: TextStyle(
  231. color: "#5E8BFF".toColor(),
  232. fontSize: 12,
  233. ),
  234. ),
  235. ),
  236. Text(
  237. "和",
  238. style: TextStyle(
  239. color: "#AFAFAF".toColor(),
  240. fontSize: 12,
  241. ),
  242. ),
  243. GestureDetector(
  244. onTap: () {
  245. BrowserPage.start(Constants.userAgreement);
  246. },
  247. child: Text(
  248. "《用户使用协议》",
  249. style: TextStyle(
  250. color: "#5E8BFF".toColor(),
  251. fontSize: 12,
  252. ),
  253. ),
  254. ),
  255. ],
  256. ),
  257. );
  258. }
  259. }