login_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/gestures.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/src/widgets/framework.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:get/get.dart';
  7. import 'package:get/get_core/src/get_main.dart';
  8. import 'package:location/base/base_page.dart';
  9. import 'package:location/data/consts/web_url.dart';
  10. import 'package:location/resource/assets.gen.dart';
  11. import 'package:location/resource/colors.gen.dart';
  12. import 'package:location/resource/string.gen.dart';
  13. import 'package:location/router/app_pages.dart';
  14. import 'package:location/utils/common_expand.dart';
  15. import '../browser/browser_view.dart';
  16. import 'login_controller.dart';
  17. class LoginPage extends BasePage<LoginController> {
  18. const LoginPage({super.key});
  19. static Future<bool> start() async {
  20. return await Get.toNamed(RoutePath.login) == true;
  21. }
  22. @override
  23. bool immersive() {
  24. return true;
  25. }
  26. @override
  27. Widget buildBody(BuildContext context) {
  28. return Obx(() {
  29. if (controller.loginStatus == LoginStatus.loading ||
  30. controller.loginStatus == LoginStatus.oneLogin) {
  31. return _buildLoadingView();
  32. } else {
  33. return _buildPhoneNumberLoginView(context);
  34. }
  35. });
  36. }
  37. Widget _buildLoadingView() {
  38. return Center(
  39. child: CircularProgressIndicator(
  40. strokeWidth: 3.5.w,
  41. valueColor: const AlwaysStoppedAnimation(ColorName.black30),
  42. ),
  43. );
  44. }
  45. Widget _buildPhoneNumberLoginView(BuildContext context) {
  46. return GestureDetector(
  47. onTap: () {
  48. // 点击空白处关闭键盘
  49. FocusScope.of(context).unfocus();
  50. },
  51. child: Stack(
  52. children: [
  53. AspectRatio(
  54. aspectRatio: 360 / 285,
  55. child: Assets.images.bgLoginHeadContainer
  56. .image(width: double.infinity)),
  57. buildLoginHeader(),
  58. SafeArea(
  59. child: Column(
  60. children: [
  61. SizedBox(height: 150.5.w),
  62. Expanded(
  63. child: Container(
  64. width: double.infinity,
  65. height: double.infinity,
  66. decoration: BoxDecoration(
  67. color: ColorName.white,
  68. borderRadius: BorderRadius.only(
  69. topLeft: Radius.circular(18.w),
  70. topRight: Radius.circular(18.w),
  71. ),
  72. ),
  73. child: Column(
  74. children: [
  75. SizedBox(height: 27.w),
  76. buildPhoneTextFiled(),
  77. SizedBox(height: 12.w),
  78. buildCodeTextFiled(),
  79. SizedBox(height: 10.w),
  80. buildPrivacyTxt(),
  81. SizedBox(height: 148.h),
  82. buildLoginBtn(),
  83. SizedBox(height: 10.w),
  84. buildOneLoginTxt()
  85. ],
  86. ),
  87. ),
  88. )
  89. ],
  90. ),
  91. )
  92. ],
  93. ),
  94. );
  95. }
  96. Widget buildOneLoginTxt() {
  97. return Obx(() {
  98. return Visibility(
  99. visible: controller.isSupportOneLogin,
  100. child: GestureDetector(
  101. onTap: controller.onOneLoginClick,
  102. child: Padding(
  103. padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.w),
  104. child: Text(StringName.oneLoginTxt,
  105. style: TextStyle(fontSize: 14.sp, color: ColorName.black50)),
  106. ),
  107. ),
  108. );
  109. });
  110. }
  111. Widget buildPrivacyTxt() {
  112. return Padding(
  113. padding: EdgeInsets.symmetric(horizontal: 24.w),
  114. child: GestureDetector(
  115. onTap: controller.onPrivacyClick,
  116. child: Row(
  117. children: [
  118. Obx(() {
  119. return Image(
  120. image: controller.isAgreePrivacy
  121. ? Assets.images.iconCheckboxSelected.provider()
  122. : Assets.images.iconCheckboxUnSelect.provider(),
  123. width: 20.w,
  124. height: 20.w);
  125. }),
  126. RichText(
  127. text: TextSpan(
  128. style: TextStyle(
  129. color: '#A7A7A7'.color,
  130. fontSize: 12.sp,
  131. decoration: TextDecoration.none),
  132. children: [
  133. TextSpan(text: StringName.loginEtPrivacyRead),
  134. buildLinkText(StringName.privacyPolicy, WebUrl.privacyPolicy),
  135. TextSpan(text: StringName.loginEtPrivacyAnd),
  136. buildLinkText(StringName.termOfService, WebUrl.userAgreement),
  137. ]))
  138. ],
  139. ),
  140. ),
  141. );
  142. }
  143. TextSpan buildLinkText(String text, String url) {
  144. return TextSpan(
  145. text: text,
  146. style: TextStyle(color: '#2F79FF'.color),
  147. recognizer: TapGestureRecognizer()
  148. ..onTap = () {
  149. BrowserPage.start(url);
  150. },
  151. );
  152. }
  153. Widget buildCodeTextFiled() {
  154. return Container(
  155. height: 50.w,
  156. margin: EdgeInsets.symmetric(horizontal: 24.w),
  157. padding: EdgeInsets.symmetric(horizontal: 12.w),
  158. decoration: BoxDecoration(
  159. color: '#FAFAFA'.color, borderRadius: BorderRadius.circular(6.w)),
  160. child: Row(
  161. children: [
  162. Expanded(
  163. child: TextField(
  164. cursorHeight: 20.w,
  165. style: TextStyle(
  166. fontSize: 16.sp,
  167. color: ColorName.primaryTextColor,
  168. fontWeight: FontWeight.bold),
  169. maxLines: 1,
  170. maxLength: 4,
  171. keyboardType: TextInputType.phone,
  172. textAlignVertical: TextAlignVertical.center,
  173. textInputAction: TextInputAction.next,
  174. decoration: InputDecoration(
  175. hintText: StringName.loginPrintVerificationCode,
  176. counterText: '',
  177. hintStyle: TextStyle(
  178. fontSize: 16.sp,
  179. color: "#A7A7A7".toColor(),
  180. fontWeight: FontWeight.normal),
  181. labelStyle: TextStyle(
  182. fontSize: 16.sp,
  183. color: ColorName.primaryTextColor,
  184. ),
  185. contentPadding: const EdgeInsets.all(0),
  186. border: const OutlineInputBorder(borderSide: BorderSide.none),
  187. enabled: true,
  188. ),
  189. onChanged: controller.onCodeChanged,
  190. ),
  191. ),
  192. buildVerificationCodeSendBtn()
  193. ],
  194. ),
  195. );
  196. }
  197. Widget buildVerificationCodeSendBtn() {
  198. return Obx(() {
  199. return GestureDetector(
  200. onTap: controller.onSendVerificationCode,
  201. child: Container(
  202. margin: EdgeInsets.only(left: 12.w),
  203. decoration: BoxDecoration(
  204. color: controller.phone.length == 11 &&
  205. controller.countDown == null
  206. ? '#7B7DFF'.color
  207. : '#337B7DFF'.color,
  208. borderRadius: BorderRadius.circular(4.w)),
  209. padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 6.w),
  210. child: Obx(() {
  211. String txt = "";
  212. if (controller.countDown != null) {
  213. txt =
  214. '${controller.countDown}${StringName.loginRetransmissionCode}';
  215. } else {
  216. txt = StringName.loginSendVerificationCode;
  217. }
  218. return Text(txt,
  219. style: TextStyle(fontSize: 14.sp, color: ColorName.white));
  220. })),
  221. );
  222. });
  223. }
  224. Widget buildPhoneTextFiled() {
  225. return Container(
  226. height: 50.w,
  227. margin: EdgeInsets.symmetric(horizontal: 24.w),
  228. padding: EdgeInsets.symmetric(horizontal: 12.w),
  229. decoration: BoxDecoration(
  230. color: '#FAFAFA'.color, borderRadius: BorderRadius.circular(6.w)),
  231. child: Row(
  232. children: [
  233. Text('+86',
  234. style: TextStyle(
  235. fontSize: 16.sp,
  236. color: '#202020'.color,
  237. fontWeight: FontWeight.bold)),
  238. SizedBox(width: 8.w),
  239. Container(width: 1.w, height: 20.w, color: '#E2E2E2'.color),
  240. SizedBox(width: 25.w),
  241. Expanded(
  242. child: TextField(
  243. cursorHeight: 20.w,
  244. style: TextStyle(
  245. fontSize: 16.sp,
  246. color: ColorName.primaryTextColor,
  247. fontWeight: FontWeight.bold),
  248. maxLines: 1,
  249. maxLength: 11,
  250. keyboardType: TextInputType.phone,
  251. textAlignVertical: TextAlignVertical.center,
  252. textInputAction: TextInputAction.next,
  253. decoration: InputDecoration(
  254. hintText: StringName.loginEtPhoneHint,
  255. counterText: '',
  256. hintStyle: TextStyle(
  257. fontSize: 16.sp,
  258. color: "#A7A7A7".toColor(),
  259. fontWeight: FontWeight.normal),
  260. labelStyle: TextStyle(
  261. fontSize: 16.sp,
  262. color: ColorName.primaryTextColor,
  263. ),
  264. contentPadding: const EdgeInsets.all(0),
  265. border: const OutlineInputBorder(borderSide: BorderSide.none),
  266. enabled: true,
  267. ),
  268. onChanged: controller.onPhoneChanged,
  269. ),
  270. )
  271. ],
  272. ),
  273. );
  274. }
  275. Widget buildLoginHeader() {
  276. return SafeArea(
  277. child: Container(
  278. margin: EdgeInsets.only(top: 23.w, left: 12.w),
  279. child: Row(
  280. children: [
  281. GestureDetector(
  282. onTap: controller.onBackClick,
  283. child: Assets.images.iconWhiteBack
  284. .image(width: 25.w, height: 25.w)),
  285. SizedBox(width: 4.w),
  286. Text(StringName.login,
  287. style: TextStyle(fontSize: 17.sp, color: ColorName.white))
  288. ],
  289. )),
  290. );
  291. }
  292. Widget buildLoginBtn() {
  293. return Obx(() {
  294. return GestureDetector(
  295. onTap: controller.onLoginClick,
  296. child: Container(
  297. decoration: BoxDecoration(
  298. color: controller.phone.length == 11 &&
  299. controller.code.isNotEmpty &&
  300. controller.isAgreePrivacy
  301. ? '#7B7DFF'.color
  302. : '#337B7DFF'.color,
  303. borderRadius: BorderRadius.circular(30.w)),
  304. width: 280.w,
  305. height: 44.w,
  306. child: Center(
  307. child: Text(StringName.login,
  308. style: TextStyle(
  309. fontSize: 16.sp,
  310. color: ColorName.white,
  311. fontWeight: FontWeight.bold)),
  312. ),
  313. ),
  314. );
  315. });
  316. }
  317. }