optimize closeConfirmDialog by using async onWindowCloseButton
This commit is contained in:
parent
d939a5ebc6
commit
7fce018eea
@ -75,9 +75,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
|||||||
backgroundColor: MyTheme.color(context).bg,
|
backgroundColor: MyTheme.color(context).bg,
|
||||||
body: DesktopTab(
|
body: DesktopTab(
|
||||||
controller: tabController,
|
controller: tabController,
|
||||||
onWindowCloseButton: () {
|
onWindowCloseButton: handleWindowCloseButton,
|
||||||
tabController.clear();
|
|
||||||
},
|
|
||||||
tail: const AddButton().paddingOnly(left: 10),
|
tail: const AddButton().paddingOnly(left: 10),
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
@ -103,4 +101,21 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
|||||||
tabController.closeBy(peerId);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,9 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
|
|||||||
backgroundColor: MyTheme.color(context).bg,
|
backgroundColor: MyTheme.color(context).bg,
|
||||||
body: DesktopTab(
|
body: DesktopTab(
|
||||||
controller: tabController,
|
controller: tabController,
|
||||||
onWindowCloseButton: () {
|
onWindowCloseButton: () async {
|
||||||
tabController.clear();
|
tabController.clear();
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
tail: AddButton().paddingOnly(left: 10),
|
tail: AddButton().paddingOnly(left: 10),
|
||||||
)),
|
)),
|
||||||
|
@ -97,9 +97,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
body: DesktopTab(
|
body: DesktopTab(
|
||||||
controller: tabController,
|
controller: tabController,
|
||||||
showTabBar: fullscreen.isFalse,
|
showTabBar: fullscreen.isFalse,
|
||||||
onWindowCloseButton: () {
|
onWindowCloseButton: handleWindowCloseButton,
|
||||||
tabController.clear();
|
|
||||||
},
|
|
||||||
tail: AddButton().paddingOnly(left: 10),
|
tail: AddButton().paddingOnly(left: 10),
|
||||||
pageViewBuilder: (pageView) {
|
pageViewBuilder: (pageView) {
|
||||||
WindowController.fromWindowId(windowId())
|
WindowController.fromWindowId(windowId())
|
||||||
@ -167,4 +165,21 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
tabController.closeBy(peerId);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ class DesktopTab extends StatelessWidget {
|
|||||||
final bool showClose;
|
final bool showClose;
|
||||||
final Widget Function(Widget pageView)? pageViewBuilder;
|
final Widget Function(Widget pageView)? pageViewBuilder;
|
||||||
final Widget? tail;
|
final Widget? tail;
|
||||||
final VoidCallback? onWindowCloseButton;
|
final Future<bool> Function()? onWindowCloseButton;
|
||||||
final TabBuilder? tabBuilder;
|
final TabBuilder? tabBuilder;
|
||||||
final LabelGetter? labelGetter;
|
final LabelGetter? labelGetter;
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ class WindowActionPanel extends StatelessWidget {
|
|||||||
final bool showMinimize;
|
final bool showMinimize;
|
||||||
final bool showMaximize;
|
final bool showMaximize;
|
||||||
final bool showClose;
|
final bool showClose;
|
||||||
final VoidCallback? onClose;
|
final Future<bool> Function()? onClose;
|
||||||
|
|
||||||
const WindowActionPanel(
|
const WindowActionPanel(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
@ -434,7 +434,8 @@ class WindowActionPanel extends StatelessWidget {
|
|||||||
message: 'Close',
|
message: 'Close',
|
||||||
icon: IconFont.close,
|
icon: IconFont.close,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
action() {
|
final res = await onClose?.call() ?? true;
|
||||||
|
if (res) {
|
||||||
if (mainTab) {
|
if (mainTab) {
|
||||||
windowManager.close();
|
windowManager.close();
|
||||||
} else {
|
} else {
|
||||||
@ -443,14 +444,6 @@ class WindowActionPanel extends StatelessWidget {
|
|||||||
WindowController.fromWindowId(windowId!).hide();
|
WindowController.fromWindowId(windowId!).hide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onClose?.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tabType != DesktopTabType.main &&
|
|
||||||
state.value.tabs.length > 1) {
|
|
||||||
closeConfirmDialog(action);
|
|
||||||
} else {
|
|
||||||
action();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isClose: true,
|
isClose: true,
|
||||||
@ -458,30 +451,28 @@ class WindowActionPanel extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
closeConfirmDialog(Function() callback) async {
|
Future<bool> closeConfirmDialog() async {
|
||||||
final res = await gFFI.dialogManager.show<bool>((setState, close) {
|
final res = await gFFI.dialogManager.show<bool>((setState, close) {
|
||||||
submit() => close(true);
|
submit() => close(true);
|
||||||
return CustomAlertDialog(
|
return CustomAlertDialog(
|
||||||
title: Row(children: [
|
title: Row(children: [
|
||||||
const Icon(Icons.warning_amber_sharp,
|
const Icon(Icons.warning_amber_sharp,
|
||||||
color: Colors.redAccent, size: 28),
|
color: Colors.redAccent, size: 28),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Text(translate("Warning")),
|
Text(translate("Warning")),
|
||||||
]),
|
]),
|
||||||
content: Text(translate("Disconnect all devices?")),
|
content: Text(translate("Disconnect all devices?")),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(onPressed: close, child: Text(translate("Cancel"))),
|
TextButton(onPressed: close, child: Text(translate("Cancel"))),
|
||||||
ElevatedButton(onPressed: submit, child: Text(translate("OK"))),
|
ElevatedButton(onPressed: submit, child: Text(translate("OK"))),
|
||||||
],
|
],
|
||||||
onSubmit: submit,
|
onSubmit: submit,
|
||||||
onCancel: close,
|
onCancel: close,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
if (res == true) {
|
return res == true;
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user