view.dart 7.7 KB

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