view.dart 7.6 KB

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