view.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../../common/api/index.dart';
  4. import '../../common/models/index.dart';
  5. import '../../common/style/index.dart';
  6. import '../../common/utils/log_util.dart';
  7. import '../../common/widgets/index.dart';
  8. import '../common/portal/index.dart';
  9. import 'apps/index.dart';
  10. import 'contact/index.dart';
  11. import 'default_index/index.dart';
  12. import 'im/index.dart';
  13. import 'index.dart';
  14. import 'settings/index.dart';
  15. class HomePage extends GetView<HomeController> {
  16. const HomePage({Key? key}) : super(key: key);
  17. /// 底部 tabBar
  18. Widget _buildBottomNavigationBar() {
  19. return Obx(() => BottomNavigationBar(
  20. items: controller.state.homeTabList.map((element) {
  21. switch (element) {
  22. case AppIndexModule.im:
  23. return BottomNavigationBarItem(
  24. icon: O2UI.badgeView(controller.state.unReadNumber,
  25. const Icon(O2IconFont.message)),
  26. activeIcon: O2UI.badgeView(controller.state.unReadNumber,
  27. const Icon(O2IconFont.message)),
  28. label: element.name());
  29. case AppIndexModule.contact:
  30. return BottomNavigationBarItem(
  31. icon: const Icon(O2IconFont.addressList),
  32. activeIcon: const Icon(O2IconFont.addressList),
  33. label: element.name());
  34. case AppIndexModule.home:
  35. return _indexBarItem();
  36. case AppIndexModule.app:
  37. return BottomNavigationBarItem(
  38. icon: const Icon(O2IconFont.apps),
  39. activeIcon: const Icon(O2IconFont.apps),
  40. label: element.name());
  41. case AppIndexModule.settings:
  42. return BottomNavigationBarItem(
  43. icon: const Icon(O2IconFont.settings),
  44. activeIcon: const Icon(O2IconFont.settings),
  45. label: element.name());
  46. }
  47. }).toList(),
  48. currentIndex: controller.state.currentIndex,
  49. type: BottomNavigationBarType.fixed,
  50. onTap: (value) => controller.handleNavBarClick(value),
  51. ));
  52. }
  53. // 主视图
  54. Widget _buildView() {
  55. return Obx(() => controller.state.showBottomBar
  56. // ? controller.getViewByIndex(controller.state.currentIndex)
  57. ? _mainPageView()
  58. : const CircularProgressIndicator());
  59. }
  60. @override
  61. Widget build(BuildContext context) {
  62. OLogger.d("HomePage build");
  63. return GetBuilder<HomeController>(
  64. builder: (_) {
  65. return WillPopScope(
  66. onWillPop: controller.onWillPop,
  67. child: Obx(() => Scaffold(
  68. backgroundColor: Theme.of(context).primaryColor,
  69. body: SafeArea(
  70. child: _buildView(),
  71. ),
  72. bottomNavigationBar: controller.state.showBottomBar
  73. ? _buildBottomNavigationBar()
  74. : Container(
  75. color: Colors.white,
  76. width: double.infinity),
  77. )));
  78. },
  79. );
  80. }
  81. /// 首页 底部 tab 按钮
  82. BottomNavigationBarItem _indexBarItem() {
  83. return BottomNavigationBarItem(
  84. icon: ProgramCenterService.to.homeBlurImageView(),
  85. activeIcon: ProgramCenterService.to.homeFocusImageView(),
  86. label: '');
  87. }
  88. /// PageView 主页
  89. Widget _mainPageView() {
  90. return Obx(() => PageView.builder(
  91. controller: controller.pageController,
  92. itemCount: controller.state.homeTabList.length,
  93. physics: const NeverScrollableScrollPhysics(),
  94. itemBuilder: (context, index) {
  95. final app = controller.state.homeTabList[index];
  96. switch (app) {
  97. case AppIndexModule.im:
  98. return KeepAliveWrapper(child: _imPageView());
  99. case AppIndexModule.contact:
  100. return KeepAliveWrapper(child: _contactPageView());
  101. case AppIndexModule.home:
  102. return KeepAliveWrapper(child: _defaultIndexPageView());
  103. case AppIndexModule.app:
  104. return KeepAliveWrapper(child: _appsPageView());
  105. case AppIndexModule.settings:
  106. return KeepAliveWrapper(child: _settingsPageView());
  107. }
  108. }));
  109. }
  110. /// 应用页面
  111. Widget _appsPageView() {
  112. final portal = ProgramCenterService.to.getExtendParamHomeTabPortal('appTabPortal');
  113. if (portal!= null && portal.portalId?.isNotEmpty == true ) {
  114. final portalId = portal.portalId!;
  115. final hiddenAppBar = portal.hiddenAppBar ?? false;
  116. final appBarTitle = portal.appBarTitle ?? 'home_tab_apps'.tr;
  117. final pageId = portal.pageId;
  118. final portalParameters = portal.portalParameters;
  119. Get.lazyPut<PortalController>(
  120. () => PortalController(initMap: {
  121. "portalId": portalId,
  122. "hiddenAppBar": hiddenAppBar,
  123. "title": appBarTitle,
  124. "pageId": pageId,
  125. "portalParameters": portalParameters
  126. }),
  127. tag: 'app_tag_$portalId');
  128. controller.portalCache[AppIndexModule.app] = portalId;
  129. return PortalPage(tag: 'app_tag_$portalId');
  130. } else {
  131. AppsBinding().dependencies();
  132. return const AppsPage();
  133. }
  134. }
  135. /// 通讯录页面
  136. Widget _contactPageView() {
  137. final portal = ProgramCenterService.to.getExtendParamHomeTabPortal('contactTabPortal');
  138. if (portal!= null && portal.portalId?.isNotEmpty == true ) {
  139. final portalId = portal.portalId!;
  140. final hiddenAppBar = portal.hiddenAppBar ?? false;
  141. final appBarTitle = portal.appBarTitle ?? 'home_tab_contact'.tr;
  142. final pageId = portal.pageId;
  143. final portalParameters = portal.portalParameters;
  144. Get.lazyPut<PortalController>(
  145. () => PortalController(initMap: {
  146. "portalId": portalId,
  147. "hiddenAppBar": hiddenAppBar,
  148. "title": appBarTitle,
  149. "pageId": pageId,
  150. "portalParameters": portalParameters
  151. }),
  152. tag: 'contact_tag_$portalId');
  153. controller.portalCache[AppIndexModule.contact] = portalId;
  154. return PortalPage(tag: 'contact_tag_$portalId');
  155. } else {
  156. ContactBinding().dependencies();
  157. return const ContactPage();
  158. }
  159. }
  160. /// 首页
  161. Widget _defaultIndexPageView() {
  162. final portal = ProgramCenterService.to.getExtendParamHomeTabPortal('indexTabPortal');
  163. if (portal!= null && portal.portalId?.isNotEmpty == true ) {
  164. final portalId = portal.portalId!;
  165. final hiddenAppBar = portal.hiddenAppBar ?? false;
  166. final appBarTitle = portal.appBarTitle ?? 'home_tab_index'.tr;
  167. final pageId = portal.pageId;
  168. final portalParameters = portal.portalParameters;
  169. Get.lazyPut<PortalController>(
  170. () => PortalController(initMap: {
  171. "portalId": portalId,
  172. "hiddenAppBar": hiddenAppBar,
  173. "title": appBarTitle,
  174. "pageId": pageId,
  175. "portalParameters": portalParameters
  176. }),
  177. tag: 'index_tag_$portalId');
  178. return PortalPage(tag: 'index_tag_$portalId');
  179. } else {
  180. var portalId = ProgramCenterService.to.homeIndexPage();
  181. if (portalId != null && portalId.isNotEmpty) {
  182. final extendParam = ProgramCenterService.to.extendParam();
  183. final indexPortalHiddenAppBar =
  184. extendParam['indexPortalHiddenAppBar'] ?? true;
  185. final indexPortalAppBarTitle =
  186. extendParam['indexPortalAppBarTitle'] ?? 'home_tab_index'.tr;
  187. Get.lazyPut<PortalController>(
  188. () => PortalController(initMap: {
  189. "portalId": portalId,
  190. "hiddenAppBar": indexPortalHiddenAppBar,
  191. "title": indexPortalAppBarTitle
  192. }),
  193. tag: 'index_tag_$portalId');
  194. controller.portalCache[AppIndexModule.home] = portalId;
  195. return PortalPage(tag: 'index_tag_$portalId');
  196. } else {
  197. DefaultIndexBinding().dependencies();
  198. return const DefaultIndexPage();
  199. }
  200. }
  201. }
  202. /// 消息页面
  203. Widget _imPageView() {
  204. final portal = ProgramCenterService.to.getExtendParamHomeTabPortal('imTabPortal');
  205. if (portal!= null && portal.portalId?.isNotEmpty == true ) {
  206. final portalId = portal.portalId!;
  207. final hiddenAppBar = portal.hiddenAppBar ?? false;
  208. final appBarTitle = portal.appBarTitle ?? 'home_tab_im'.tr;
  209. final pageId = portal.pageId;
  210. final portalParameters = portal.portalParameters;
  211. Get.lazyPut<PortalController>(
  212. () => PortalController(initMap: {
  213. "portalId": portalId,
  214. "hiddenAppBar": hiddenAppBar,
  215. "title": appBarTitle,
  216. "pageId": pageId,
  217. "portalParameters": portalParameters
  218. }),
  219. tag: 'im_tag_$portalId');
  220. controller.portalCache[AppIndexModule.im] = portalId;
  221. return PortalPage(tag: 'im_tag_$portalId');
  222. } else {
  223. ImBinding().dependencies();
  224. return const ImPage();
  225. }
  226. }
  227. /// 设置页面
  228. Widget _settingsPageView() {
  229. final portal = ProgramCenterService.to.getExtendParamHomeTabPortal('settingsTabPortal');
  230. if (portal!= null && portal.portalId?.isNotEmpty == true ) {
  231. final portalId = portal.portalId!;
  232. final hiddenAppBar = portal.hiddenAppBar ?? false;
  233. final appBarTitle = portal.appBarTitle ?? 'home_tab_settings'.tr;
  234. final pageId = portal.pageId;
  235. final portalParameters = portal.portalParameters;
  236. Get.lazyPut<PortalController>(
  237. () => PortalController(initMap: {
  238. "portalId": portalId,
  239. "hiddenAppBar": hiddenAppBar,
  240. "title": appBarTitle,
  241. "pageId": pageId,
  242. "portalParameters": portalParameters
  243. }),
  244. tag: 'settings_tag_$portalId');
  245. controller.portalCache[AppIndexModule.settings] = portalId;
  246. return PortalPage(tag: 'settings_tag_$portalId');
  247. } else {
  248. SettingsBinding().dependencies();
  249. return const SettingsPage();
  250. }
  251. }
  252. }