login_page.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. // ignore_for_file: slash_for_doc_comments
  2. import 'package:cs_resources/constants/color_constants.dart';
  3. import 'package:cs_resources/generated/assets.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/gestures.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter/widgets.dart';
  8. import 'package:get/get.dart';
  9. import 'package:plugin_basic/base/base_stateful_page.dart';
  10. import 'package:plugin_basic/base/base_state.dart';
  11. import 'package:plugin_basic/base/mixin_state_lifecycle.dart';
  12. import 'package:plugin_basic/service/app_config_service.dart';
  13. import 'package:plugin_basic/utils/ext_get_nav.dart';
  14. import 'package:router/path/router_path.dart';
  15. import 'package:shared/utils/device_utils.dart';
  16. import 'package:shared/utils/log_utils.dart';
  17. import 'package:shared/utils/screen_util.dart';
  18. import 'package:widgets/ext/ex_widget.dart';
  19. import 'package:widgets/my_button.dart';
  20. import 'package:widgets/my_load_image.dart';
  21. import 'package:widgets/my_text_field.dart';
  22. import 'package:widgets/my_text_view.dart';
  23. import 'package:widgets/shatter/custom_radio_check.dart';
  24. import 'package:widgets/widget_export.dart';
  25. import 'login_controller.dart';
  26. import 'login_state.dart';
  27. /*
  28. App 登录页面
  29. */
  30. class LoginPage extends BaseStatefulPage<LoginController> {
  31. LoginPage({super.key});
  32. //启动当前页面
  33. static void startInstance() {
  34. return Get.start(RouterPath.authLogin, launchModel: LaunchModel.standard);
  35. }
  36. static void startWithPopAll() {
  37. Get.offAllNamed(RouterPath.authLogin);
  38. }
  39. @override
  40. State<LoginPage> createState() => _LoginPageState();
  41. @override
  42. LoginController createRawController() {
  43. return LoginController();
  44. }
  45. }
  46. /**
  47. * 页面
  48. */
  49. class _LoginPageState extends BaseState<LoginPage, LoginController> with StateLifecycle {
  50. late LoginState state;
  51. @override
  52. void initState() {
  53. super.initState();
  54. state = controller.state;
  55. }
  56. @override
  57. void dispose() {
  58. Get.delete<LoginController>();
  59. super.dispose();
  60. }
  61. @override
  62. Widget build(BuildContext context) {
  63. Log.d("LoginPage Lifecycle - build走了一遍");
  64. return autoCtlGetBuilder(
  65. builder: (controller) {
  66. return Scaffold(
  67. body: Container(
  68. width: double.infinity,
  69. height: double.infinity,
  70. decoration: const BoxDecoration(
  71. gradient: LinearGradient(
  72. colors: [
  73. Color(0xFF091D44),
  74. Color(0xFF245A8A),
  75. Color(0xFF7F7CEC),
  76. ],
  77. begin: Alignment.topCenter,
  78. end: Alignment.bottomCenter,
  79. ),
  80. ),
  81. child: Column(
  82. mainAxisSize: MainAxisSize.max,
  83. crossAxisAlignment: CrossAxisAlignment.center,
  84. children: [
  85. //当前选择的国家,这个不跟随滚动
  86. Align(
  87. alignment: Alignment.topRight,
  88. child: Row(
  89. mainAxisSize: MainAxisSize.min,
  90. crossAxisAlignment: CrossAxisAlignment.center,
  91. children: [
  92. Obx(() {
  93. return MyTextView(
  94. ConfigService.to.selectCountry.value == 1
  95. ? "Singapore".tr
  96. : ConfigService.to.selectCountry.value == 2
  97. ? "United Kingdom".tr
  98. : ConfigService.to.selectCountry.value == 3
  99. ? "Malaysia".tr
  100. : ConfigService.to.selectCountry.value == 4
  101. ? "Netherlands".tr
  102. : "Vietnam".tr,
  103. textColor: ColorConstants.white,
  104. isFontMedium: true,
  105. marginRight: 5,
  106. fontSize: 15,
  107. );
  108. }),
  109. const MyAssetImage(
  110. Assets.baseServiceTriangleDropDown,
  111. width: 8,
  112. height: 5,
  113. ),
  114. ],
  115. ).onTap(() => controller.gotoSelectCountryPage()).marginOnly(right: 20, top: ScreenUtil.getStatusBarH(context) + 20),
  116. ),
  117. // 底部滚动的布局
  118. SingleChildScrollView(
  119. scrollDirection: Axis.vertical,
  120. physics: const BouncingScrollPhysics(),
  121. child: Column(
  122. mainAxisSize: MainAxisSize.max,
  123. crossAxisAlignment: CrossAxisAlignment.center,
  124. children: [
  125. MyTextView(
  126. "Casual Labour System",
  127. textColor: ColorConstants.white,
  128. isFontBold: true,
  129. fontSize: 35,
  130. marginTop: 20,
  131. fontStyle: FontStyle.italic,
  132. textAlign: TextAlign.center,
  133. marginLeft: 50,
  134. marginRight: 50,
  135. ),
  136. //中间的输入框布局
  137. Container(
  138. width: double.infinity,
  139. margin: const EdgeInsets.symmetric(vertical: 45, horizontal: 15),
  140. padding: const EdgeInsets.symmetric(vertical: 33, horizontal: 20),
  141. decoration: BoxDecoration(
  142. color: const Color(0xFF4DCFF6).withOpacity(0.2), // 设置背景颜色和不透明度
  143. borderRadius: BorderRadius.circular(5.0), // 设置圆角
  144. ),
  145. child: Center(
  146. child: Column(
  147. crossAxisAlignment: CrossAxisAlignment.start,
  148. children: [
  149. //登录文本
  150. MyTextView(
  151. "Email".tr,
  152. isFontMedium: true,
  153. fontSize: 17,
  154. textColor: ColorConstants.white,
  155. ),
  156. // 登录表单 - 账号
  157. _buildInputLayout(
  158. "code",
  159. textInputAction: TextInputAction.next,
  160. errorText: state.codeErrorText,
  161. onSubmit: (formKey, value) {
  162. state.formData[formKey]!['focusNode'].unfocus();
  163. FocusScope.of(context).requestFocus(state.formData['password']!['focusNode']);
  164. },
  165. ),
  166. //密码文本
  167. MyTextView(
  168. "Password".tr,
  169. isFontMedium: true,
  170. fontSize: 17,
  171. textColor: ColorConstants.white,
  172. marginTop: 18,
  173. ),
  174. // 登录表单 - 密码
  175. _buildInputLayout(
  176. "password",
  177. obscureText: !state.pwdVisibility,
  178. errorText: state.passwordErrorText,
  179. showRightIcon: true,
  180. rightWidget: IconButton(
  181. highlightColor: Colors.transparent,
  182. splashColor: Colors.transparent,
  183. icon: state.pwdVisibility
  184. ? const MyAssetImage(
  185. Assets.cptAuthPasswordShowIcon,
  186. width: 21,
  187. height: 21,
  188. color: ColorConstants.white,
  189. )
  190. : const MyAssetImage(
  191. Assets.cptAuthPasswordHideIcon,
  192. width: 21,
  193. height: 21,
  194. color: ColorConstants.white,
  195. ),
  196. onPressed: () {
  197. controller.switchPwdVisibility();
  198. },
  199. ),
  200. onSubmit: (formKey, value) {
  201. state.formData[formKey]!['focusNode'].unfocus();
  202. controller.doInputLogin();
  203. },
  204. ),
  205. //选择签到功能还是全功能
  206. Obx(() {
  207. return Visibility(
  208. visible: ConfigService.to.selectCountry.value == 0, //这是越南的逻辑,新加坡与英国不需要
  209. child: CustomRadioCheck(
  210. options: state.loginOption,
  211. onOptionSelected: (index, text) {
  212. state.loginOptionPosition = index;
  213. },
  214. ).marginOnly(top: 20),
  215. );
  216. }),
  217. //登录按钮
  218. MyButton(
  219. type: ClickType.throttle,
  220. milliseconds: 500,
  221. onPressed: () {
  222. FocusScope.of(context).unfocus();
  223. controller.doInputLogin();
  224. },
  225. text: "Log in".tr,
  226. textColor: ColorConstants.white,
  227. fontSize: 16,
  228. radius: 22.5,
  229. backgroundColor: hexToColor("#FFBB1B"),
  230. fontWeight: FontWeight.w500,
  231. ).marginOnly(top: 20),
  232. //注册入口
  233. Visibility(
  234. visible: !DeviceUtils.isAndroid,
  235. child: _buildRichText(),
  236. ),
  237. ],
  238. ),
  239. ), // 传递子部件
  240. ),
  241. ],
  242. )).expanded(),
  243. ],
  244. ),
  245. ),
  246. );
  247. },
  248. );
  249. }
  250. @override
  251. void onStart() {
  252. Log.d("LoginPage Lifecycle - onStart");
  253. }
  254. @override
  255. void onStop() {
  256. Log.d("LoginPage Lifecycle - onStop");
  257. }
  258. @override
  259. void onResume() {
  260. Log.d("LoginPage Lifecycle - onResume");
  261. }
  262. @override
  263. void onPause() {
  264. Log.d("LoginPage Lifecycle - onPause");
  265. }
  266. //底部的注册文本
  267. Widget _buildRichText() {
  268. return Align(
  269. alignment: Alignment.center,
  270. child: RichText(
  271. text: TextSpan(
  272. style: const TextStyle(fontSize: 14.0, fontWeight: FontWeight.w500, color: ColorConstants.textGrayAECAE5),
  273. children: <TextSpan>[
  274. TextSpan(
  275. text: "Don’t have an account?".tr,
  276. style: const TextStyle(color: ColorConstants.textGrayAECAE5),
  277. ),
  278. TextSpan(
  279. text: "Sign up".tr,
  280. style: const TextStyle(color: ColorConstants.textYellowFFBB1B),
  281. recognizer: TapGestureRecognizer()
  282. ..onTap = () {
  283. //去登录页面
  284. controller.gotoSignUpPage();
  285. },
  286. ),
  287. ],
  288. ),
  289. ),
  290. ).marginOnly(top: 23);
  291. }
  292. /// 输入框 账号与密码
  293. Widget _buildInputLayout(
  294. String key, {
  295. double marginTop = 0,
  296. bool? showRightIcon = false, //是否展示右侧的布局
  297. Widget? rightWidget, //右侧的布局
  298. TextInputType textInputType = TextInputType.text,
  299. String? errorText,
  300. bool obscureText = false,
  301. TextInputAction textInputAction = TextInputAction.done,
  302. Function? onSubmit,
  303. }) {
  304. return IgnoreKeyboardDismiss(
  305. child: MyTextField(
  306. key,
  307. state.formData[key]!['value'],
  308. hintText: state.formData[key]!['hintText'],
  309. hintStyle: TextStyle(
  310. color: hexToColor("#AECAE5"),
  311. fontSize: 15.0,
  312. fontWeight: FontWeight.w500,
  313. ),
  314. controller: state.formData[key]!['controller'],
  315. focusNode: state.formData[key]!['focusNode'],
  316. margin: EdgeInsets.only(top: marginTop),
  317. showDivider: true,
  318. dividerColor: hexToColor("#7BABC8"),
  319. style: const TextStyle(
  320. color: ColorConstants.white,
  321. fontSize: 15.0,
  322. fontWeight: FontWeight.w500,
  323. ),
  324. inputType: textInputType,
  325. height: 35,
  326. textInputAction: textInputAction,
  327. onSubmit: onSubmit,
  328. cursorColor: ColorConstants.white,
  329. obscureText: obscureText,
  330. errorText: errorText,
  331. showLeftIcon: true,
  332. showRightIcon: showRightIcon,
  333. rightWidget: rightWidget,
  334. ),
  335. );
  336. }
  337. }