view.dart 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. maxLength: 11,
  93. cursorColor: ColorName.colorPrimary,
  94. keyboardType: TextInputType.phone,
  95. textAlignVertical: TextAlignVertical.center,
  96. textInputAction: TextInputAction.next,
  97. decoration: InputDecoration(
  98. hintText: '输入手机号码',
  99. counterText: '',
  100. hintStyle: TextStyle(fontSize: 16, color: "#AFAFAF".toColor()),
  101. labelStyle: const TextStyle(
  102. fontSize: 16,
  103. color: ColorName.primaryTextColor,
  104. ),
  105. contentPadding: const EdgeInsets.all(0),
  106. border: const OutlineInputBorder(borderSide: BorderSide.none),
  107. enabled: true,
  108. ),
  109. style: TextStyle(fontSize: 14.sp),
  110. onChanged: (value) {
  111. controller.setPhone(value);
  112. },
  113. ),
  114. );
  115. }
  116. // 验证码输入框
  117. Widget _buildCodeTextField() {
  118. return Container(
  119. margin: EdgeInsets.only(top: 36.h, left: 28.w, right: 28.w),
  120. alignment: Alignment.center,
  121. height: 44.h,
  122. decoration: BoxDecoration(
  123. border: Border(
  124. bottom: BorderSide(
  125. width: 1.0,
  126. color: "#F0F0F0".toColor(),
  127. ),
  128. ),
  129. ),
  130. child: Row(
  131. children: [
  132. Expanded(
  133. child: TextField(
  134. maxLines: 1,
  135. maxLength: 4,
  136. keyboardType: TextInputType.number,
  137. inputFormatters: [FilteringTextInputFormatter.digitsOnly],
  138. cursorColor: ColorName.colorPrimary,
  139. textAlignVertical: TextAlignVertical.center,
  140. textInputAction: TextInputAction.done,
  141. decoration: InputDecoration(
  142. counterText: '',
  143. hintText: '输入验证码',
  144. hintStyle: TextStyle(fontSize: 16, color: "#AFAFAF".toColor()),
  145. labelStyle: const TextStyle(
  146. fontSize: 16,
  147. color: ColorName.primaryTextColor,
  148. ),
  149. contentPadding: const EdgeInsets.all(0),
  150. border: const OutlineInputBorder(borderSide: BorderSide.none),
  151. enabled: true,
  152. ),
  153. style: TextStyle(fontSize: 14.sp),
  154. onChanged: (value) {
  155. controller.setCode(value);
  156. },
  157. ),
  158. ),
  159. LoginCodeBtn(
  160. onTapCallback: () {
  161. controller.getUserCode();
  162. },
  163. available: true,
  164. ),
  165. ],
  166. ),
  167. );
  168. }
  169. // 登录按钮
  170. Widget _buildLoginBtn() {
  171. return GestureDetector(
  172. onTap: () {
  173. controller.login();
  174. },
  175. child: Container(
  176. margin: EdgeInsets.only(
  177. top: 54.h,
  178. left: 28.w,
  179. right: 28.w,
  180. ),
  181. height: 48.h,
  182. alignment: Alignment.center,
  183. decoration: BoxDecoration(
  184. gradient: LinearGradient(
  185. colors: ['#6177F2'.toColor(), '#8B9DFF'.toColor()],
  186. stops: const [0, 1.0],
  187. ),
  188. borderRadius: BorderRadius.circular(8),
  189. ),
  190. child: const Text(
  191. "登录",
  192. style: TextStyle(
  193. color: ColorName.white,
  194. fontSize: 16,
  195. fontWeight: FontWeight.w500,
  196. ),
  197. ),
  198. ),
  199. );
  200. }
  201. Widget _buildAgreeText() {
  202. return Container(
  203. margin: EdgeInsets.only(left: 28.w, top: 16.h),
  204. child: Row(
  205. children: [
  206. Obx(
  207. () {
  208. return GestureDetector(
  209. onTap: () {
  210. controller.isAgree.value = !controller.isAgree.value;
  211. },
  212. child: SizedBox(
  213. width: 20.w,
  214. height: 20.w,
  215. child: controller.isAgree.value
  216. ? Assets.images.iconSelectTrue.image()
  217. : Assets.images.iconSelectFalse.image()),
  218. );
  219. },
  220. ),
  221. Text(
  222. "我已阅读并同意",
  223. style: TextStyle(
  224. color: "#AFAFAF".toColor(),
  225. fontSize: 12,
  226. ),
  227. ),
  228. GestureDetector(
  229. onTap: () {
  230. if (GetPlatform.isIOS) {
  231. BrowserPage.start(Constants.privacyPolicyIos);
  232. } else {
  233. BrowserPage.start(Constants.privacyPolicy);
  234. }
  235. },
  236. child: Text(
  237. "《隐私政策》",
  238. style: TextStyle(
  239. color: "#5E8BFF".toColor(),
  240. fontSize: 12,
  241. ),
  242. ),
  243. ),
  244. Text(
  245. "和",
  246. style: TextStyle(
  247. color: "#AFAFAF".toColor(),
  248. fontSize: 12,
  249. ),
  250. ),
  251. GestureDetector(
  252. onTap: () {
  253. BrowserPage.start(Constants.userAgreement);
  254. },
  255. child: Text(
  256. "《用户使用协议》",
  257. style: TextStyle(
  258. color: "#5E8BFF".toColor(),
  259. fontSize: 12,
  260. ),
  261. ),
  262. ),
  263. ],
  264. ),
  265. );
  266. }
  267. }