Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window destroy on android and iOS #3733

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/flet/lib/src/utils/desktop.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:window_manager/window_manager.dart';
import 'package:window_to_front/window_to_front.dart';
import 'package:flutter/services.dart';

import '../models/window_media_data.dart';

Expand Down Expand Up @@ -244,9 +246,15 @@ Future blurWindow() async {
}

Future destroyWindow() async {
if (isDesktop()) {
if (isDesktop() || isMobile()) {
debugPrint("destroyWindow()");
Comment on lines -247 to 248
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Remove redundant platform check as all cases are handled specifically.

The isDesktop() || isMobile() check is no longer necessary since all platforms are handled in the subsequent conditions. Consider removing this check and keeping only the debug print statement outside of any condition.

Suggested change
if (isDesktop()) {
if (isDesktop() || isMobile()) {
debugPrint("destroyWindow()");
debugPrint("destroyWindow()");

}
Comment on lines 248 to +251
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider renaming the function to reflect its expanded functionality

The destroyWindow() function now handles application exit for both desktop and mobile platforms. Consider renaming it to something more general like exitApplication() or terminateApp() to accurately reflect its broader purpose.

Suggested change
Future destroyWindow() async {
if (isDesktop()) {
if (isDesktop() || isMobile()) {
debugPrint("destroyWindow()");
}
Future terminateApp() async {
if (isDesktop() || isMobile()) {
debugPrint("terminateApp()");
}

if (isDesktop()) {
await windowManager.destroy();
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
exit(0);
FeodorFitsner marked this conversation as resolved.
Show resolved Hide resolved
} else if (defaultTargetPlatform == TargetPlatform.android) {
SystemNavigator.pop();
}
}

Expand Down