optimize closeConfirmDialog by using async onWindowCloseButton

This commit is contained in:
csf
2022-09-09 19:29:19 +08:00
parent d939a5ebc6
commit 7fce018eea
4 changed files with 63 additions and 41 deletions

View File

@@ -75,9 +75,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
backgroundColor: MyTheme.color(context).bg,
body: DesktopTab(
controller: tabController,
onWindowCloseButton: () {
tabController.clear();
},
onWindowCloseButton: handleWindowCloseButton,
tail: const AddButton().paddingOnly(left: 10),
)),
),
@@ -103,4 +101,21 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
tabController.closeBy(peerId);
}
}
Future<bool> handleWindowCloseButton() async {
final connLength = tabController.state.value.tabs.length;
if (connLength < 1) {
return true;
} else if (connLength == 1) {
final currentConn = tabController.state.value.tabs[0];
handleTabCloseButton(currentConn.key);
return false;
} else {
final res = await closeConfirmDialog();
if (res) {
tabController.clear();
}
return res;
}
}
}