login_page.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. ? "Korea".tr
  98. : "Vietnam".tr,
  99. textColor: ColorConstants.white,
  100. isFontMedium: true,
  101. marginRight: 5,
  102. fontSize: 15,
  103. );
  104. }),
  105. const MyAssetImage(
  106. Assets.baseServiceTriangleDropDown,
  107. width: 8,
  108. height: 5,
  109. ),
  110. ],
  111. ).onTap(() => controller.gotoSelectCountryPage()).marginOnly(right: 20, top: ScreenUtil.getStatusBarH(context) + 20),
  112. ),
  113. // 底部滚动的布局
  114. SingleChildScrollView(
  115. scrollDirection: Axis.vertical,
  116. physics: const BouncingScrollPhysics(),
  117. child: Column(
  118. mainAxisSize: MainAxisSize.max,
  119. crossAxisAlignment: CrossAxisAlignment.center,
  120. children: [
  121. MyTextView(
  122. "Casual Labour System",
  123. textColor: ColorConstants.white,
  124. isFontBold: true,
  125. fontSize: 35,
  126. marginTop: 20,
  127. fontStyle: FontStyle.italic,
  128. textAlign: TextAlign.center,
  129. marginLeft: 50,
  130. marginRight: 50,
  131. ),
  132. //中间的输入框布局
  133. Container(
  134. width: double.infinity,
  135. margin: const EdgeInsets.symmetric(vertical: 45, horizontal: 15),
  136. padding: const EdgeInsets.symmetric(vertical: 33, horizontal: 20),
  137. decoration: BoxDecoration(
  138. color: const Color(0xFF4DCFF6).withOpacity(0.2), // 设置背景颜色和不透明度
  139. borderRadius: BorderRadius.circular(5.0), // 设置圆角
  140. ),
  141. child: Center(
  142. child: Column(
  143. crossAxisAlignment: CrossAxisAlignment.start,
  144. children: [
  145. //登录文本
  146. MyTextView(
  147. "Email".tr,
  148. isFontMedium: true,
  149. fontSize: 17,
  150. textColor: ColorConstants.white,
  151. ),
  152. // 登录表单 - 账号
  153. _buildInputLayout(
  154. "code",
  155. textInputAction: TextInputAction.next,
  156. errorText: state.codeErrorText,
  157. onSubmit: (formKey, value) {
  158. state.formData[formKey]!['focusNode'].unfocus();
  159. FocusScope.of(context).requestFocus(state.formData['password']!['focusNode']);
  160. },
  161. ),
  162. //密码文本
  163. MyTextView(
  164. "Password".tr,
  165. isFontMedium: true,
  166. fontSize: 17,
  167. textColor: ColorConstants.white,
  168. marginTop: 18,
  169. ),
  170. // 登录表单 - 密码
  171. _buildInputLayout(
  172. "password",
  173. obscureText: !state.pwdVisibility,
  174. errorText: state.passwordErrorText,
  175. showRightIcon: true,
  176. rightWidget: IconButton(
  177. highlightColor: Colors.transparent,
  178. splashColor: Colors.transparent,
  179. icon: state.pwdVisibility
  180. ? const MyAssetImage(
  181. Assets.cptAuthPasswordShowIcon,
  182. width: 21,
  183. height: 21,
  184. color: ColorConstants.white,
  185. )
  186. : const MyAssetImage(
  187. Assets.cptAuthPasswordHideIcon,
  188. width: 21,
  189. height: 21,
  190. color: ColorConstants.white,
  191. ),
  192. onPressed: () {
  193. controller.switchPwdVisibility();
  194. },
  195. ),
  196. onSubmit: (formKey, value) {
  197. state.formData[formKey]!['focusNode'].unfocus();
  198. controller.doInputLogin();
  199. },
  200. ),
  201. //选择签到功能还是全功能
  202. Obx(() {
  203. return Visibility(
  204. visible: ConfigService.to.selectCountry.value != 1,
  205. child: CustomRadioCheck(
  206. options: state.loginOption,
  207. onOptionSelected: (index, text) {
  208. state.loginOptionPosition = index;
  209. },
  210. ).marginOnly(top: 20),
  211. );
  212. }),
  213. //登录按钮
  214. MyButton(
  215. type: ClickType.throttle,
  216. milliseconds: 500,
  217. onPressed: () {
  218. FocusScope.of(context).unfocus();
  219. controller.doInputLogin();
  220. },
  221. text: "Log in".tr,
  222. textColor: ColorConstants.white,
  223. fontSize: 16,
  224. radius: 22.5,
  225. backgroundColor: hexToColor("#FFBB1B"),
  226. fontWeight: FontWeight.w500,
  227. ).marginOnly(top: 20),
  228. //注册入口
  229. Visibility(
  230. visible: !DeviceUtils.isAndroid,
  231. child: _buildRichText(),
  232. ),
  233. ],
  234. ),
  235. ), // 传递子部件
  236. ),
  237. ],
  238. )).expanded(),
  239. ],
  240. ),
  241. ),
  242. );
  243. },
  244. );
  245. }
  246. @override
  247. void onStart() {
  248. Log.d("LoginPage Lifecycle - onStart");
  249. }
  250. @override
  251. void onStop() {
  252. Log.d("LoginPage Lifecycle - onStop");
  253. }
  254. @override
  255. void onResume() {
  256. Log.d("LoginPage Lifecycle - onResume");
  257. }
  258. @override
  259. void onPause() {
  260. Log.d("LoginPage Lifecycle - onPause");
  261. }
  262. //底部的注册文本
  263. Widget _buildRichText() {
  264. return Align(
  265. alignment: Alignment.center,
  266. child: RichText(
  267. text: TextSpan(
  268. style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w500, color: ColorConstants.textGrayAECAE5),
  269. children: <TextSpan>[
  270. TextSpan(
  271. text: "Don’t have an account?".tr,
  272. style: TextStyle(color: ColorConstants.textGrayAECAE5),
  273. ),
  274. TextSpan(
  275. text: "Sign up".tr,
  276. style: TextStyle(color: ColorConstants.textYellowFFBB1B),
  277. recognizer: TapGestureRecognizer()
  278. ..onTap = () {
  279. //去登录页面
  280. controller.gotoSignUpPage();
  281. },
  282. ),
  283. ],
  284. ),
  285. ),
  286. ).marginOnly(top: 23);
  287. }
  288. /// 输入框 账号与密码
  289. Widget _buildInputLayout(
  290. String key, {
  291. double marginTop = 0,
  292. bool? showRightIcon = false, //是否展示右侧的布局
  293. Widget? rightWidget, //右侧的布局
  294. TextInputType textInputType = TextInputType.text,
  295. String? errorText,
  296. bool obscureText = false,
  297. TextInputAction textInputAction = TextInputAction.done,
  298. Function? onSubmit,
  299. }) {
  300. return IgnoreKeyboardDismiss(
  301. child: MyTextField(
  302. key,
  303. state.formData[key]!['value'],
  304. hintText: state.formData[key]!['hintText'],
  305. hintStyle: TextStyle(
  306. color: hexToColor("#AECAE5"),
  307. fontSize: 15.0,
  308. fontWeight: FontWeight.w500,
  309. ),
  310. controller: state.formData[key]!['controller'],
  311. focusNode: state.formData[key]!['focusNode'],
  312. margin: EdgeInsets.only(top: marginTop),
  313. showDivider: true,
  314. dividerColor: hexToColor("#7BABC8"),
  315. style: TextStyle(
  316. color: ColorConstants.white,
  317. fontSize: 15.0,
  318. fontWeight: FontWeight.w500,
  319. ),
  320. inputType: textInputType,
  321. height: 35,
  322. textInputAction: textInputAction,
  323. onSubmit: onSubmit,
  324. cursorColor: ColorConstants.white,
  325. obscureText: obscureText,
  326. errorText: errorText,
  327. showLeftIcon: true,
  328. showRightIcon: showRightIcon,
  329. rightWidget: rightWidget,
  330. ),
  331. );
  332. }
  333. }