main_page_header.dart 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/gestures.dart';
  3. import 'package:flyinsono/architecture/utils/window__change_helpler.dart';
  4. import 'package:flyinsono/global.dart';
  5. import 'package:flyinsono/lab/color/lab_colors.dart';
  6. import 'package:flyinsono/lab/manager/page_manager.dart';
  7. import 'package:flyinsono/lab/pages/lab_main/index.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flyinsono/lab/pages/lab_main/widgets/logo_item.dart';
  10. import 'package:flyinsono/lab/pages/lab_main/widgets/user_label.dart';
  11. import 'package:flyinsono/lab/pages/lab_main/widgets/widgets.dart';
  12. import 'package:flyinsono/pages/others/title_bar_buttons.dart';
  13. import 'package:get/get.dart';
  14. import 'package:fis_common/index.dart';
  15. class MainPageHeader extends GetView<LabMainController> {
  16. const MainPageHeader({Key? key}) : super(key: key);
  17. @override
  18. Widget build(BuildContext context) {
  19. final content = Container(
  20. color: LabColors.mainPageHeaderColor,
  21. height: 50,
  22. child: Row(
  23. children: [
  24. if (!Global.isVStationSlave)
  25. GetBuilder<LabMainController>(
  26. id: LabMainController.headerLogoId,
  27. builder: (_) {
  28. return LogoItem(
  29. isActive: PageManager.ins.activeTabHash ==
  30. PageManager.ins.tabTitles[0].tabHash,
  31. onTap: () {
  32. PageManager.ins
  33. .changeTabByHash(PageManager.ins.tabTitles[0].tabHash);
  34. },
  35. );
  36. },
  37. ),
  38. Expanded(
  39. child: Stack(
  40. children: [
  41. GetBuilder<LabMainController>(
  42. id: LabMainController.headerTabsId,
  43. builder: (_) {
  44. List<Widget> tabs = [];
  45. if (PageManager.ins.tabViews.isEmpty) {
  46. return Container();
  47. }
  48. for (var i = 0; i < PageManager.ins.tabTitles.length; i++) {
  49. final int tabHash = PageManager.ins.tabTitles[i].tabHash;
  50. tabs.add(
  51. TabItem(
  52. index: i,
  53. isActive: PageManager.ins.activeTabHash == tabHash,
  54. text: PageManager.ins.tabTitles[i].title,
  55. onTap: () {
  56. PageManager.ins.changeTabByHash(tabHash);
  57. },
  58. onClose: PageManager.ins.isFixedTab(tabHash)
  59. ? null
  60. : () => PageManager.ins.closeTab(tabHash),
  61. ),
  62. );
  63. }
  64. return Listener(
  65. onPointerSignal: (pointerSignal) {
  66. if (pointerSignal is PointerScrollEvent) {
  67. controller
  68. .scrollTabByPointerScrollEvent(pointerSignal);
  69. }
  70. },
  71. child: SingleChildScrollView(
  72. scrollDirection: Axis.horizontal,
  73. controller: controller.tabScrollController,
  74. physics: const NeverScrollableScrollPhysics(),
  75. child: Row(
  76. children: tabs,
  77. ),
  78. ),
  79. );
  80. },
  81. ),
  82. Row(
  83. children: [
  84. Obx(
  85. () => controller.state.showLeftMoreIcon
  86. ? ShowMoreIcon(
  87. isLeft: true,
  88. onTap: () {
  89. controller.scrollTabToLeft();
  90. },
  91. )
  92. : Container(),
  93. ),
  94. Expanded(child: Container()),
  95. Obx(
  96. () => controller.state.showRightMoreIcon
  97. ? ShowMoreIcon(
  98. isLeft: false,
  99. onTap: () {
  100. controller.scrollTabToRight();
  101. },
  102. )
  103. : Container(),
  104. ),
  105. ],
  106. )
  107. ],
  108. ),
  109. ),
  110. Container(
  111. margin: const EdgeInsets.symmetric(horizontal: 10),
  112. child: Row(
  113. children: [
  114. if (!Global.isVStationSlave) UserLabel(),
  115. if (FPlatform.isWindows && !Global.isVStationSlave)
  116. _buildWindowOperateButtons(),
  117. ],
  118. ),
  119. ),
  120. ],
  121. ),
  122. );
  123. if (FPlatform.isPureWeb) {
  124. return content;
  125. } else {
  126. return GestureDetector(
  127. onPanStart: (event) {
  128. WindowChangeHelper.onStartDrag();
  129. },
  130. onPanEnd: (e) {
  131. WindowChangeHelper.onEndDrag();
  132. },
  133. onDoubleTap: () {
  134. WindowChangeHelper.onMaximize();
  135. },
  136. onPanCancel: () {
  137. WindowChangeHelper.onEndDrag();
  138. },
  139. child: content,
  140. );
  141. }
  142. }
  143. ///最大化、最小化、关闭按钮
  144. Widget _buildWindowOperateButtons() {
  145. return TitleBarButtons(
  146. WindowChangeHelper.onMinimize,
  147. WindowChangeHelper.onClose,
  148. WindowChangeHelper.onMaximize,
  149. LabColors.text100,
  150. LabColors.tabBarButtonColor,
  151. hoverColor: LabColors.hoverButtonColor,
  152. isLabHeader: true,
  153. isShowNotification: false,
  154. );
  155. }
  156. }