From 63cb816b7de0cd7685fb7c3a91760f839acb3feb Mon Sep 17 00:00:00 2001 From: csf Date: Thu, 8 Sep 2022 20:43:27 +0800 Subject: [PATCH] fix: close one connection tab will dispose all tabs (Obx) --- .../desktop/pages/connection_tab_page.dart | 122 +++++++++--------- 1 file changed, 59 insertions(+), 63 deletions(-) diff --git a/flutter/lib/desktop/pages/connection_tab_page.dart b/flutter/lib/desktop/pages/connection_tab_page.dart index bf12f443c..3dd825f36 100644 --- a/flutter/lib/desktop/pages/connection_tab_page.dart +++ b/flutter/lib/desktop/pages/connection_tab_page.dart @@ -44,12 +44,11 @@ class _ConnectionTabPageState extends State { tabController.jumpBy(peerId); clientClose(ffi(peerId).dialogManager); }, - page: Obx(() => RemotePage( - key: ValueKey(peerId), - id: peerId, - tabBarHeight: - fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, - )))); + page: RemotePage( + key: ValueKey(peerId), + id: peerId, + tabBarHeight: fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, + ))); } } @@ -81,12 +80,11 @@ class _ConnectionTabPageState extends State { tabController.jumpBy(id); clientClose(ffi(id).dialogManager); }, - page: Obx(() => RemotePage( - key: ValueKey(id), - id: id, - tabBarHeight: - fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, - )))); + page: RemotePage( + key: ValueKey(id), + id: id, + tabBarHeight: fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, + ))); } else if (call.method == "onDestroy") { tabController.clear(); } @@ -104,57 +102,55 @@ class _ConnectionTabPageState extends State { border: Border.all(color: MyTheme.color(context).border!)), child: Scaffold( backgroundColor: MyTheme.color(context).bg, - body: Obx(() => DesktopTab( - controller: tabController, - showTabBar: fullscreen.isFalse, - onWindowCloseButton: () { - tabController.clear(); - }, - tail: AddButton().paddingOnly(left: 10), - pageViewBuilder: (pageView) { - WindowController.fromWindowId(windowId()) - .setFullscreen(fullscreen.isTrue); - return pageView; - }, - tabBuilder: (key, icon, label, themeConf) => Obx(() { - final connectionType = ConnectionTypeState.find(key); - if (!connectionType.isValid()) { - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - icon, - label, - ], - ); - } else { - final msgDirect = translate( - connectionType.direct.value == - ConnectionType.strDirect - ? 'Direct Connection' - : 'Relay Connection'); - final msgSecure = translate( - connectionType.secure.value == - ConnectionType.strSecure - ? 'Secure Connection' - : 'Insecure Connection'); - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - icon, - Tooltip( - message: '$msgDirect\n$msgSecure', - child: Image.asset( - 'assets/${connectionType.secure.value}${connectionType.direct.value}.png', - width: themeConf.iconSize, - height: themeConf.iconSize, - ).paddingOnly(right: 5), - ), - label, - ], - ); - } - }), - ))), + body: DesktopTab( + controller: tabController, + showTabBar: fullscreen.isFalse, + onWindowCloseButton: () { + tabController.clear(); + }, + tail: AddButton().paddingOnly(left: 10), + pageViewBuilder: (pageView) { + WindowController.fromWindowId(windowId()) + .setFullscreen(fullscreen.isTrue); + return pageView; + }, + tabBuilder: (key, icon, label, themeConf) => Obx(() { + final connectionType = ConnectionTypeState.find(key); + if (!connectionType.isValid()) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + icon, + label, + ], + ); + } else { + final msgDirect = translate(connectionType.direct.value == + ConnectionType.strDirect + ? 'Direct Connection' + : 'Relay Connection'); + final msgSecure = translate(connectionType.secure.value == + ConnectionType.strSecure + ? 'Secure Connection' + : 'Insecure Connection'); + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + icon, + Tooltip( + message: '$msgDirect\n$msgSecure', + child: Image.asset( + 'assets/${connectionType.secure.value}${connectionType.direct.value}.png', + width: themeConf.iconSize, + height: themeConf.iconSize, + ).paddingOnly(right: 5), + ), + label, + ], + ); + } + }), + )), ), )); }