replace tabview with pageview to remove animation

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-08-18 10:54:09 +08:00
parent e02e88f0ee
commit 41e5f6d0de
6 changed files with 260 additions and 199 deletions

View File

@@ -20,28 +20,28 @@ class ConnectionTabPage extends StatefulWidget {
State<ConnectionTabPage> createState() => _ConnectionTabPageState(params);
}
class _ConnectionTabPageState extends State<ConnectionTabPage>
with TickerProviderStateMixin {
class _ConnectionTabPageState extends State<ConnectionTabPage> {
// refactor List<int> when using multi-tab
// this singleton is only for test
RxList<TabInfo> tabs = RxList<TabInfo>.empty(growable: true);
late Rx<TabController> tabController;
static final Rx<int> _selected = 0.obs;
static final Rx<String> _fullscreenID = "".obs;
IconData icon = Icons.desktop_windows_sharp;
final IconData selectedIcon = Icons.desktop_windows_sharp;
final IconData unselectedIcon = Icons.desktop_windows_outlined;
var connectionMap = RxList<Widget>.empty(growable: true);
_ConnectionTabPageState(Map<String, dynamic> params) {
if (params['id'] != null) {
tabs.add(TabInfo(label: params['id'], icon: icon));
tabs.add(TabInfo(
label: params['id'],
selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon));
}
}
@override
void initState() {
super.initState();
tabController = TabController(length: tabs.length, vsync: this).obs;
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
print(
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
@@ -50,8 +50,12 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
final args = jsonDecode(call.arguments);
final id = args['id'];
window_on_top(windowId());
DesktopTabBar.onAdd(this, tabController, tabs, _selected,
TabInfo(label: id, icon: icon));
DesktopTabBar.onAdd(
tabs,
TabInfo(
label: id,
selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon));
} else if (call.method == "onDestroy") {
print(
"executing onDestroy hook, closing ${tabs.map((tab) => tab.label).toList()}");
@@ -74,18 +78,16 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
Obx(() => Visibility(
visible: _fullscreenID.value.isEmpty,
child: DesktopTabBar(
controller: tabController,
tabs: tabs,
onTabClose: onRemoveId,
selected: _selected,
dark: isDarkTheme(),
mainTab: false,
))),
Expanded(child: Obx(() {
WindowController.fromWindowId(windowId())
.setFullscreen(_fullscreenID.value.isNotEmpty);
return TabBarView(
controller: tabController.value,
return PageView(
controller: DesktopTabBar.controller.value,
children: tabs
.map((tab) => RemotePage(
key: ValueKey(tab.label),
@@ -103,7 +105,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
}
void onRemoveId(String id) {
DesktopTabBar.onClose(this, tabController, tabs, id);
ffi(id).close();
if (tabs.length == 0) {
WindowController.fromWindowId(windowId()).close();

View File

@@ -13,20 +13,19 @@ class DesktopTabPage extends StatefulWidget {
State<DesktopTabPage> createState() => _DesktopTabPageState();
}
class _DesktopTabPageState extends State<DesktopTabPage>
with TickerProviderStateMixin {
late Rx<TabController> tabController;
class _DesktopTabPageState extends State<DesktopTabPage> {
late RxList<TabInfo> tabs;
static final Rx<int> _selected = 0.obs;
@override
void initState() {
super.initState();
tabs = RxList.from([
TabInfo(label: kTabLabelHomePage, icon: Icons.home_sharp, closable: false)
TabInfo(
label: kTabLabelHomePage,
selectedIcon: Icons.home_sharp,
unselectedIcon: Icons.home_outlined,
closable: false)
], growable: true);
tabController =
TabController(length: tabs.length, vsync: this, initialIndex: 0).obs;
}
@override
@@ -35,17 +34,14 @@ class _DesktopTabPageState extends State<DesktopTabPage>
body: Column(
children: [
DesktopTabBar(
controller: tabController,
tabs: tabs,
onTabClose: onTabClose,
selected: _selected,
dark: isDarkTheme(),
mainTab: true,
onAddSetting: onAddSetting,
),
Obx((() => Expanded(
child: TabBarView(
controller: tabController.value,
child: PageView(
controller: DesktopTabBar.controller.value,
children: tabs.map((tab) {
switch (tab.label) {
case kTabLabelHomePage:
@@ -62,12 +58,12 @@ class _DesktopTabPageState extends State<DesktopTabPage>
);
}
void onTabClose(String label) {
DesktopTabBar.onClose(this, tabController, tabs, label);
}
void onAddSetting() {
DesktopTabBar.onAdd(this, tabController, tabs, _selected,
TabInfo(label: kTabLabelSettingPage, icon: Icons.build));
DesktopTabBar.onAdd(
tabs,
TabInfo(
label: kTabLabelSettingPage,
selectedIcon: Icons.build_sharp,
unselectedIcon: Icons.build_outlined));
}
}

View File

@@ -19,25 +19,25 @@ class FileManagerTabPage extends StatefulWidget {
State<FileManagerTabPage> createState() => _FileManagerTabPageState(params);
}
class _FileManagerTabPageState extends State<FileManagerTabPage>
with TickerProviderStateMixin {
class _FileManagerTabPageState extends State<FileManagerTabPage> {
// refactor List<int> when using multi-tab
// this singleton is only for test
RxList<TabInfo> tabs = List<TabInfo>.empty(growable: true).obs;
late Rx<TabController> tabController;
static final Rx<int> _selected = 0.obs;
IconData icon = Icons.file_copy_sharp;
final IconData selectedIcon = Icons.file_copy_sharp;
final IconData unselectedIcon = Icons.file_copy_outlined;
_FileManagerTabPageState(Map<String, dynamic> params) {
if (params['id'] != null) {
tabs.add(TabInfo(label: params['id'], icon: icon));
tabs.add(TabInfo(
label: params['id'],
selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon));
}
}
@override
void initState() {
super.initState();
tabController = TabController(length: tabs.length, vsync: this).obs;
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
print(
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
@@ -46,8 +46,12 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
final args = jsonDecode(call.arguments);
final id = args['id'];
window_on_top(windowId());
DesktopTabBar.onAdd(this, tabController, tabs, _selected,
TabInfo(label: id, icon: icon));
DesktopTabBar.onAdd(
tabs,
TabInfo(
label: id,
selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon));
} else if (call.method == "onDestroy") {
print(
"executing onDestroy hook, closing ${tabs.map((tab) => tab.label).toList()}");
@@ -68,17 +72,15 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
body: Column(
children: [
DesktopTabBar(
controller: tabController,
tabs: tabs,
onTabClose: onRemoveId,
selected: _selected,
dark: isDarkTheme(),
mainTab: false,
),
Expanded(
child: Obx(
() => TabBarView(
controller: tabController.value,
() => PageView(
controller: DesktopTabBar.controller.value,
children: tabs
.map((tab) => FileManagerPage(
key: ValueKey(tab.label),
@@ -92,8 +94,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
}
void onRemoveId(String id) {
DesktopTabBar.onClose(this, tabController, tabs, id);
ffi(id).close();
ffi("ft_$id").close();
if (tabs.length == 0) {
WindowController.fromWindowId(windowId()).close();
}