main_page.dart 6.7 KB

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