view.dart 8.1 KB

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