main_page.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import 'package:cs_resources/constants/color_constants.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:domain/entity/home_module.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:get/get.dart';
  7. import 'package:plugin_basic/base/base_stateful_page.dart';
  8. import 'package:plugin_basic/base/base_state.dart';
  9. import 'package:plugin_basic/base/mixin_state_lifecycle.dart';
  10. import 'package:plugin_basic/service/user_service.dart';
  11. import 'package:plugin_basic/utils/ext_get_nav.dart';
  12. import 'package:cs_resources/local/theme/theme_config.dart';
  13. import 'package:router/path/router_path.dart';
  14. import 'package:shared/utils/log_utils.dart';
  15. import 'package:shared/utils/screen_util.dart';
  16. import 'package:widgets/double_tap_back_exit_app.dart';
  17. import 'package:widgets/ext/ex_widget.dart';
  18. import 'package:widgets/load_state_layout.dart';
  19. import 'package:widgets/my_load_image.dart';
  20. import 'package:widgets/my_text_view.dart';
  21. import 'package:widgets/widget_export.dart';
  22. import 'main_controller.dart';
  23. import 'main_item_module.dart';
  24. import 'main_state.dart';
  25. /*
  26. App首页页面
  27. */
  28. class MainPage extends BaseStatefulPage<MainController> {
  29. MainPage({super.key});
  30. //启动当前页面
  31. static void startInstance() {
  32. return Get.start(RouterPath.main);
  33. }
  34. static void startWithPopAll() {
  35. Get.offAllNamed(RouterPath.main);
  36. }
  37. @override
  38. State<MainPage> createState() => _MainPageState();
  39. @override
  40. MainController createRawController() {
  41. return MainController();
  42. }
  43. }
  44. class _MainPageState extends BaseState<MainPage, MainController> with StateLifecycle {
  45. late MainState state;
  46. @override
  47. void initState() {
  48. super.initState();
  49. state = controller.state;
  50. }
  51. @override
  52. void dispose() {
  53. Get.delete<MainController>();
  54. super.dispose();
  55. }
  56. @override
  57. void onResume() {
  58. super.onResume();
  59. Log.d("MainPage Lifecycle - onResume");
  60. }
  61. @override
  62. void onPause() {
  63. super.onPause();
  64. Log.d("MainPage Lifecycle - onPause");
  65. }
  66. @override
  67. void onStop() {
  68. super.onStop();
  69. Log.d("MainPage Lifecycle - onStop");
  70. }
  71. @override
  72. void onStart() {
  73. super.onStart();
  74. Log.d("MainPage Lifecycle - onStart");
  75. }
  76. @override
  77. Widget build(BuildContext context) {
  78. Log.d("MainPage Lifecycle - build走了一遍");
  79. //双击退出应用
  80. return DoubleTapBackExitApp(
  81. child: AnnotatedRegion<SystemUiOverlayStyle>(
  82. value: ThemeConfig.systemUiOverlayStyleLightThemeWhite,
  83. child: autoCtlGetBuilder(builder: (controller) {
  84. return Scaffold(
  85. body: SafeArea(
  86. bottom: true,
  87. top: false,
  88. //真正的 Content 布局,使用PageView保存状态
  89. child: Container(
  90. width: double.infinity,
  91. height: double.infinity,
  92. padding: EdgeInsets.only(top: ScreenUtil.getStatusBarH(context)),
  93. decoration: const BoxDecoration(
  94. gradient: LinearGradient(
  95. colors: [
  96. Color(0xFF091D44),
  97. Color(0xFF245A8A),
  98. Color(0xFF7F7CEC),
  99. ],
  100. begin: Alignment.topCenter,
  101. end: Alignment.bottomCenter,
  102. ),
  103. ),
  104. child: Column(
  105. mainAxisSize: MainAxisSize.max,
  106. crossAxisAlignment: CrossAxisAlignment.start,
  107. children: [
  108. Row(
  109. mainAxisSize: MainAxisSize.max,
  110. mainAxisAlignment: MainAxisAlignment.start,
  111. crossAxisAlignment: CrossAxisAlignment.center,
  112. children: [
  113. // 酒店的名字
  114. Obx(() {
  115. return MyTextView(
  116. UserService.to.getHotelInfo.hotelName ?? "-",
  117. textColor: ColorConstants.white,
  118. isTextEllipsis: true,
  119. maxLines: 2,
  120. isFontBold: true,
  121. fontSize: 21,
  122. );
  123. }).expanded(),
  124. //设置图标,点击进入设置页面
  125. const MyAssetImage(Assets.mainHomeSetting, width: 33, height: 33).onTap(() => controller.gotoSettingPage()),
  126. ],
  127. ),
  128. //欢迎的文本+姓名
  129. Obx(() {
  130. return MyTextView(
  131. "${"Welcome".tr} ${UserService.to.getHotelInfo.name ?? "-"}",
  132. textColor: ColorConstants.textGray9EB0C1,
  133. isTextEllipsis: true,
  134. isFontMedium: true,
  135. marginTop: 5,
  136. marginBottom: 15,
  137. fontSize: 18,
  138. );
  139. }),
  140. //底部的列表
  141. EasyRefresh(
  142. controller: controller.refreshController,
  143. onRefresh: controller.onRefresh,
  144. child: LoadStateLayout(
  145. state: controller.loadingState,
  146. errorMessage: controller.errorMessage,
  147. errorRetry: () {
  148. controller.retryRequest();
  149. },
  150. successSliverWidget: [
  151. //接口控制显示的模块
  152. SliverGrid(
  153. delegate: SliverChildBuilderDelegate(
  154. (context, index) {
  155. return ModuleItem(state.datas[index], () {
  156. controller.gotoModulePage(state.datas[index]);
  157. });
  158. },
  159. childCount: state.datas.length,
  160. ),
  161. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  162. crossAxisCount: 2, // 每行2个项目
  163. mainAxisSpacing: 5, // 主轴方向的间距
  164. crossAxisSpacing: 5, // 交叉轴方向的间距
  165. childAspectRatio: 171 / 161, // 子项目的宽高比
  166. ),
  167. ),
  168. ],
  169. ),
  170. ).expanded(),
  171. ],
  172. ).paddingSymmetric(horizontal: 15, vertical: 17),
  173. ),
  174. ),
  175. );
  176. }),
  177. ),
  178. );
  179. }
  180. }