view.dart 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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/index.dart';
  7. import '../../../common/widgets/index.dart';
  8. import 'index.dart';
  9. class AppsPage extends GetView<AppsController> {
  10. const AppsPage({Key? key}) : super(key: key);
  11. @override
  12. Widget build(BuildContext context) {
  13. return GetBuilder<AppsController>(
  14. builder: (_) {
  15. return Scaffold(
  16. appBar:
  17. AppBar(title: Obx(() => Text(controller.state.title)), actions: [
  18. TextButton(
  19. onPressed: controller.clickEditMyAppTopBtn,
  20. child: Obx(() => Text(
  21. controller.state.isEdit ? 'save'.tr : 'edit'.tr,
  22. style: AppTheme.whitePrimaryTextStyle,
  23. )))
  24. ]),
  25. body: SafeArea(
  26. child: Container(
  27. color: Theme.of(context).scaffoldBackgroundColor,
  28. child: ListView(
  29. children: [
  30. ProgramCenterService.to.appPageImageView(),
  31. Obx(() => appBoxView(context, 'app_type_my'.tr, controller.state.myAppList, true)),
  32. const SizedBox(height: 10),
  33. Container(child: appListView(context))
  34. ],
  35. )),
  36. ),
  37. );
  38. },
  39. );
  40. }
  41. Widget appListView(BuildContext context) {
  42. return Column(
  43. children: [
  44. Obx(() => appBoxView(
  45. context, 'app_type_native'.tr, controller.state.nativeList, false)),
  46. const SizedBox(height: 10),
  47. Obx(() => appBoxView(
  48. context, 'app_type_portal'.tr, controller.state.portalList, false))
  49. ],
  50. );
  51. }
  52. ///
  53. /// 应用列表方块
  54. ///
  55. Widget appBoxView(
  56. BuildContext context, String title, List<AppFrontData?> appList, bool isMyApp) {
  57. final screenWidth = MediaQuery.of(context).size.width;
  58. final itemAxisCount = screenWidth > 560 ? 6 : (screenWidth > 375 ? 5 : 4);
  59. final itemWidth = (screenWidth - 50 - (itemAxisCount - 1) * 5) / itemAxisCount;
  60. const itemHeight = 60;
  61. final ratio = itemWidth / itemHeight;
  62. OLogger.d('screenWidth:$screenWidth, itemWidth: $itemWidth, itemHeight: $itemHeight, ratio: $ratio');
  63. return Container(
  64. color: Theme.of(context).colorScheme.background,
  65. width: double.infinity,
  66. child: Padding(
  67. padding:
  68. const EdgeInsets.only(top: 10, bottom: 5, left: 15, right: 15),
  69. child: Column(
  70. crossAxisAlignment: CrossAxisAlignment.start,
  71. children: [
  72. Text(title, style: Theme.of(context).textTheme.bodyLarge),
  73. const SizedBox(height: 5),
  74. Padding(
  75. padding: const EdgeInsets.all(10),
  76. child: GridView.count(
  77. shrinkWrap: true,
  78. physics: const NeverScrollableScrollPhysics(),
  79. crossAxisCount: itemAxisCount,
  80. mainAxisSpacing: 10,
  81. crossAxisSpacing: 5,
  82. childAspectRatio: ratio,
  83. children: appList.map((element) {
  84. if (element == null) {
  85. return Container();
  86. }
  87. return appItemView(context, element, false);
  88. }).toList()))
  89. ],
  90. )),
  91. );
  92. }
  93. ///
  94. /// 我的应用列表方块
  95. ///
  96. // Widget myAppBoxView(BuildContext context) {
  97. // final screenWidth = MediaQuery.of(context).size.width;
  98. // final itemAxisCount = screenWidth > 560 ? 6 : (screenWidth > 375 ? 5 : 4);
  99. // final itemWidth = (screenWidth - 50 - (itemAxisCount - 1) * 5) / itemAxisCount;
  100. // const itemHeight = 60;
  101. // final ratio = itemWidth / itemHeight;
  102. // OLogger.d('screenWidth:$screenWidth, itemWidth: $itemWidth, itemHeight: $itemHeight, ratio: $ratio');
  103. // return Obx(() => Container(
  104. // color: Theme.of(context).colorScheme.background,
  105. // width: double.infinity,
  106. // child: Padding(
  107. // padding: const EdgeInsets.only(
  108. // top: 10, bottom: 5, left: 15, right: 15),
  109. // child: Column(
  110. // crossAxisAlignment: CrossAxisAlignment.start,
  111. // children: [
  112. // Text('app_type_my'.tr,
  113. // style: Theme.of(context).textTheme.bodyLarge),
  114. // const SizedBox(height: 5),
  115. // Padding(
  116. // padding: const EdgeInsets.all(10),
  117. // child: controller.state.myAppList.isEmpty
  118. // ? Container()
  119. // : GridView.count(
  120. // shrinkWrap: true,
  121. // crossAxisCount: itemAxisCount,
  122. // mainAxisSpacing: 10,
  123. // crossAxisSpacing: 5,
  124. // childAspectRatio: ratio,
  125. // children:
  126. // controller.state.myAppList.map((element) {
  127. // if (element == null) {
  128. // return Container();
  129. // }
  130. // return appItemView(context, element, true);
  131. // }).toList()))
  132. // ],
  133. // )),
  134. // ));
  135. // }
  136. ///
  137. /// 单个应用View
  138. /// @param isMyApp 是否主页应用上显示,编辑的时候右上角小图标不一样
  139. ///
  140. Widget appItemView(BuildContext context, AppFrontData element, bool isMyApp) {
  141. return Obx(() => controller.state.isEdit
  142. ? GestureDetector(
  143. onTap: () => isMyApp
  144. ? controller.removeApp2MyList(element)
  145. : (controller.isInMyApp(element)
  146. ? controller.removeApp2MyList(element)
  147. : controller.addApp2MyList(element)),
  148. child: Stack(
  149. children: [
  150. _appItemView(context, element),
  151. Positioned(
  152. right: 0,
  153. top: 0,
  154. child: AssetsImageView(
  155. isMyApp
  156. ? 'icon_app_del.png'
  157. : (controller.isInMyApp(element)
  158. ? 'icon_app_del.png'
  159. : 'icon_app_add.png'),
  160. width: 12,
  161. height: 12,
  162. )),
  163. ],
  164. ))
  165. : GestureDetector(
  166. onTap: () => controller.openApp(element),
  167. child: _appItemView(context, element),
  168. ));
  169. }
  170. /// 应用 Item
  171. Widget _appItemView(BuildContext context, AppFrontData element) {
  172. var showName = element.displayName ?? '';
  173. if (showName.trim().isEmpty) {
  174. showName = element.name ?? '';
  175. }
  176. return Column(children: [
  177. // Icon图标,原生应用是本地图标,门户应用是url
  178. _appItemImageWithBadges(element),
  179. Expanded(
  180. flex: 1,
  181. child: Center(
  182. child: Text(showName,
  183. softWrap: true,
  184. style: Theme.of(context).textTheme.bodyMedium)))
  185. ]);
  186. }
  187. /// 应用图标 加上角标
  188. /// 编辑的时候不显示角标
  189. Widget _appItemImageWithBadges(AppFrontData element) {
  190. return Obx(() => controller.state.isEdit
  191. ? _appItemImage(element)
  192. : O2UI.badgeView((element.showNumber ?? 0), _appItemImage(element)));
  193. }
  194. /// 应用图标
  195. Widget _appItemImage(AppFrontData element) {
  196. Map<String, String> headers = {};
  197. headers[O2ApiManager.instance.tokenName] =
  198. O2ApiManager.instance.o2User?.token ?? '';
  199. return (element.type == O2AppTypeEnum.native)
  200. ? AssetsImageView(
  201. element.nativeEnum?.assetPath ?? 'app_task.png',
  202. width: 36,
  203. height: 36,
  204. )
  205. : Image(
  206. image: NetworkImage(element.portalIconUrl!, headers: headers),
  207. alignment: Alignment.center,
  208. width: 36,
  209. height: 36,
  210. fit: BoxFit.fill);
  211. }
  212. }