123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import 'package:flutter/material.dart';
- import 'package:flutter_hbb/common.dart';
- import 'package:flutter_hbb/consts.dart';
- import 'package:flutter_hbb/desktop/pages/desktop_home_page.dart';
- import 'package:flutter_hbb/desktop/pages/desktop_setting_page.dart';
- import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
- import 'package:flutter_hbb/models/platform_model.dart';
- import 'package:flutter_hbb/models/state_model.dart';
- import 'package:get/get.dart';
- import 'package:window_manager/window_manager.dart';
- // import 'package:flutter/services.dart';
- import '../../common/shared_state.dart';
- class DesktopTabPage extends StatefulWidget {
- const DesktopTabPage({Key? key}) : super(key: key);
- @override
- State<DesktopTabPage> createState() => _DesktopTabPageState();
- static void onAddSetting(
- {SettingsTabKey initialPage = SettingsTabKey.general}) {
- try {
- DesktopTabController tabController = Get.find<DesktopTabController>();
- tabController.add(TabInfo(
- key: kTabLabelSettingPage,
- label: kTabLabelSettingPage,
- selectedIcon: Icons.build_sharp,
- unselectedIcon: Icons.build_outlined,
- page: DesktopSettingPage(
- key: const ValueKey(kTabLabelSettingPage),
- initialTabkey: initialPage,
- )));
- } catch (e) {
- debugPrintStack(label: '$e');
- }
- }
- }
- class _DesktopTabPageState extends State<DesktopTabPage>
- with WidgetsBindingObserver {
- final tabController = DesktopTabController(tabType: DesktopTabType.main);
- final RxBool _block = false.obs;
- // bool mouseIn = false;
- _DesktopTabPageState() {
- RemoteCountState.init();
- Get.put<DesktopTabController>(tabController);
- tabController.add(TabInfo(
- key: kTabLabelHomePage,
- label: kTabLabelHomePage,
- selectedIcon: Icons.home_sharp,
- unselectedIcon: Icons.home_outlined,
- closable: false,
- page: DesktopHomePage(
- key: const ValueKey(kTabLabelHomePage),
- )));
- if (bind.isIncomingOnly()) {
- tabController.onSelected = (key) {
- if (key == kTabLabelHomePage) {
- windowManager.setSize(getIncomingOnlyHomeSize());
- setResizable(false);
- } else {
- windowManager.setSize(getIncomingOnlySettingsSize());
- setResizable(true);
- }
- };
- }
- }
- @override
- void didChangeAppLifecycleState(AppLifecycleState state) {
- super.didChangeAppLifecycleState(state);
- if (state == AppLifecycleState.resumed) {
- shouldBeBlocked(_block, canBeBlocked);
- } else if (state == AppLifecycleState.inactive) {}
- }
- @override
- void initState() {
- super.initState();
- // HardwareKeyboard.instance.addHandler(_handleKeyEvent);
- WidgetsBinding.instance.addObserver(this);
- }
- /*
- bool _handleKeyEvent(KeyEvent event) {
- if (!mouseIn && event is KeyDownEvent) {
- print('key down: ${event.logicalKey}');
- shouldBeBlocked(_block, canBeBlocked);
- }
- return false; // allow it to propagate
- }
- */
- @override
- void dispose() {
- // HardwareKeyboard.instance.removeHandler(_handleKeyEvent);
- WidgetsBinding.instance.removeObserver(this);
- Get.delete<DesktopTabController>();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- final tabWidget = Container(
- child: Scaffold(
- backgroundColor: Theme.of(context).colorScheme.background,
- body: DesktopTab(
- controller: tabController,
- tail: Offstage(
- offstage: bind.isIncomingOnly() || bind.isDisableSettings(),
- child: ActionIcon(
- message: 'Settings',
- icon: IconFont.menu,
- onTap: DesktopTabPage.onAddSetting,
- isClose: false,
- ),
- ),
- blockTab: _block,
- )));
- return isMacOS || kUseCompatibleUiMode
- ? tabWidget
- : Obx(
- () => DragToResizeArea(
- resizeEdgeSize: stateGlobal.resizeEdgeSize.value,
- enableResizeEdges: windowManagerEnableResizeEdges,
- child: tabWidget,
- ),
- );
- }
- }
|