login_page.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import 'package:cs_resources/constants/color_constants.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:plugin_basic/base/base_stateful_page.dart';
  6. import 'package:plugin_basic/base/base_state.dart';
  7. import 'package:plugin_basic/base/mixin_state_lifecycle.dart';
  8. import 'package:plugin_basic/utils/ext_get_nav.dart';
  9. import 'package:router/path/router_path.dart';
  10. import 'package:shared/utils/log_utils.dart';
  11. import 'package:widgets/ext/ex_widget.dart';
  12. import 'package:widgets/my_button.dart';
  13. import 'package:widgets/my_load_image.dart';
  14. import 'package:widgets/my_text_field.dart';
  15. import 'package:widgets/my_text_view.dart';
  16. import 'package:widgets/widget_export.dart';
  17. import 'login_controller.dart';
  18. import 'login_state.dart';
  19. /*
  20. App 登录页面
  21. */
  22. class LoginPage extends BaseStatefulPage<LoginController> {
  23. LoginPage({super.key});
  24. //启动当前页面
  25. static void startInstance() {
  26. return Get.start(RouterPath.AUTH_LOGIN, launchModel: LaunchModel.standard);
  27. }
  28. static void startWithPopAll() {
  29. Get.offAllNamed(RouterPath.AUTH_LOGIN);
  30. }
  31. @override
  32. State<LoginPage> createState() => _MainPageState();
  33. @override
  34. LoginController createRawController() {
  35. return LoginController();
  36. }
  37. }
  38. /**
  39. * 页面
  40. */
  41. class _MainPageState extends BaseState<LoginPage, LoginController> with StateLifecycle {
  42. late LoginState state;
  43. @override
  44. void initState() {
  45. super.initState();
  46. state = controller.state;
  47. }
  48. @override
  49. void dispose() {
  50. Get.delete<LoginController>();
  51. super.dispose();
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. Log.d("LoginPage Lifecycle - build走了一遍");
  56. return autoCtlGetBuilder(
  57. builder: (controller) {
  58. return Scaffold(
  59. body: Container(
  60. width: double.infinity,
  61. height: double.infinity,
  62. decoration: const BoxDecoration(
  63. gradient: LinearGradient(
  64. colors: [
  65. Color(0xFF091D44),
  66. Color(0xFF245A8A),
  67. Color(0xFF7F7CEC),
  68. ],
  69. begin: Alignment.topCenter,
  70. end: Alignment.bottomCenter,
  71. ),
  72. ),
  73. child: SingleChildScrollView(
  74. scrollDirection: Axis.vertical,
  75. physics: const BouncingScrollPhysics(),
  76. child: Column(
  77. mainAxisSize: MainAxisSize.max,
  78. crossAxisAlignment: CrossAxisAlignment.center,
  79. children: [
  80. //顶部Logo
  81. MyAssetImage(
  82. Assets.assetsYyBusinessTopLogo,
  83. width: 164.5,
  84. height: 101,
  85. ).marginOnly(top: 75),
  86. //中间的输入框布局
  87. Container(
  88. width: double.infinity,
  89. margin: EdgeInsets.symmetric(vertical: 45, horizontal: 15),
  90. padding: EdgeInsets.symmetric(vertical: 33, horizontal: 20),
  91. decoration: BoxDecoration(
  92. color: Color(0xFF4DCFF6).withOpacity(0.2), // 设置背景颜色和不透明度
  93. borderRadius: BorderRadius.circular(5.0), // 设置圆角
  94. ),
  95. child: Center(
  96. child: Column(
  97. crossAxisAlignment: CrossAxisAlignment.start,
  98. children: [
  99. //登录文本
  100. MyTextView(
  101. "Login Code".tr,
  102. isFontMedium: true,
  103. fontSize: 17,
  104. textColor: ColorConstants.white,
  105. ),
  106. // 登录表单 - 账号
  107. _buildInputLayout(
  108. "code",
  109. textInputAction: TextInputAction.next,
  110. errorText: controller.codeErrorText,
  111. onSubmit: (formKey, value) {
  112. state.formData[formKey]!['focusNode'].unfocus();
  113. FocusScope.of(context).requestFocus(state.formData['password']!['focusNode']);
  114. },
  115. ),
  116. //密码文本
  117. MyTextView(
  118. "Password".tr,
  119. isFontMedium: true,
  120. fontSize: 17,
  121. textColor: ColorConstants.white,
  122. marginTop: 18,
  123. ),
  124. // 登录表单 - 密码
  125. _buildInputLayout(
  126. "password",
  127. obscureText: !controller.pwdVisibility,
  128. errorText: controller.passwordErrorText,
  129. showRightIcon: true,
  130. rightWidget: IconButton(
  131. highlightColor: Colors.transparent,
  132. splashColor: Colors.transparent,
  133. icon: controller.pwdVisibility
  134. ? const MyAssetImage(
  135. Assets.cptAuthPasswordShowIcon,
  136. width: 21,
  137. height: 21,
  138. color: ColorConstants.white,
  139. )
  140. : const MyAssetImage(
  141. Assets.cptAuthPasswordHideIcon,
  142. width: 21,
  143. height: 21,
  144. color: ColorConstants.white,
  145. ),
  146. onPressed: () {
  147. controller.switchPwdVisibility();
  148. },
  149. ),
  150. onSubmit: (formKey, value) {
  151. state.formData[formKey]!['focusNode'].unfocus();
  152. controller.doInputLogin();
  153. },
  154. ),
  155. MyButton(
  156. type: ClickType.throttle,
  157. milliseconds: 500,
  158. onPressed: () {
  159. FocusScope.of(context).unfocus();
  160. controller.doInputLogin();
  161. },
  162. text: "Log in".tr,
  163. textColor: ColorConstants.white,
  164. fontSize: 16,
  165. radius: 22.5,
  166. backgroundColor: hexToColor("#FFBB1B"),
  167. fontWeight: FontWeight.w500,
  168. ).marginOnly(top: 31)
  169. ],
  170. ),
  171. ), // 传递子部件
  172. ),
  173. ],
  174. ),
  175. ),
  176. ),
  177. );
  178. },
  179. );
  180. }
  181. /// 输入框 账号与密码
  182. _buildInputLayout(
  183. String key, {
  184. double marginTop = 0,
  185. bool? showRightIcon = false, //是否展示右侧的布局
  186. Widget? rightWidget, //右侧的布局
  187. TextInputType textInputType = TextInputType.text,
  188. String? errorText,
  189. bool obscureText = false,
  190. TextInputAction textInputAction = TextInputAction.done,
  191. Function? onSubmit,
  192. }) {
  193. return IgnoreKeyboardDismiss(
  194. child: MyTextField(
  195. key,
  196. state.formData[key]!['value'],
  197. hintText: state.formData[key]!['hintText'],
  198. hintStyle: TextStyle(
  199. color: hexToColor("#AECAE5"),
  200. fontSize: 15.0,
  201. fontWeight: FontWeight.w500,
  202. ),
  203. controller: state.formData[key]!['controller'],
  204. focusNode: state.formData[key]!['focusNode'],
  205. margin: EdgeInsets.only(top: marginTop),
  206. showDivider: true,
  207. dividerColor: hexToColor("#7BABC8"),
  208. style: TextStyle(
  209. color: ColorConstants.white,
  210. fontSize: 15.0,
  211. fontWeight: FontWeight.w500,
  212. ),
  213. inputType: textInputType,
  214. height: 35,
  215. textInputAction: textInputAction,
  216. onSubmit: onSubmit,
  217. cursorColor: ColorConstants.white,
  218. obscureText: obscureText,
  219. errorText: errorText,
  220. showLeftIcon: true,
  221. showRightIcon: showRightIcon,
  222. rightWidget: rightWidget,
  223. ),
  224. );
  225. }
  226. }