leanflutter / window_manager

This plugin allows Flutter desktop apps to resizing and repositioning the window.
https://pub.dev/packages/window_manager
MIT License
676 stars 177 forks source link

Exception has occurred #453

Closed EnziinSystem closed 3 months ago

EnziinSystem commented 3 months ago

I already know that the current project only supports Windows, Linux and MacOS and does not support mobile platforms.

However, because it has changed so much source code as below, the application cannot guarantee cross-platform capabilities.

import 'package:window_manager/window_manager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Must add this line.
  await windowManager.ensureInitialized();

  WindowOptions windowOptions = const WindowOptions(
    size: Size(800, 600),
    center: true,
    backgroundColor: Colors.transparent,
    skipTaskbar: false,
    titleBarStyle: TitleBarStyle.hidden,
  );
  windowManager.waitUntilReadyToShow(windowOptions, () async {
    await windowManager.show();
    await windowManager.focus();
    await windowManager.setFullScreen(true);
  });

  runApp(const MyApp());
}

The error message on Android:

Exception has occurred.
MissingPluginException (MissingPluginException(No implementation found for method ensureInitialized on channel window_manager))

If I want to use the mobile application then I have to clone the source code project and remove the windows_manager package.

This takes away the cross-platform capabilities of the Flutter app.

cybrox commented 3 months ago

You can check the defaultTargetPlatform from Flutter and just wrap that code in an if block.

We've been doing this for a long time in one of our apps that's running on mobile and desktop and it has worked flawlessly.

lijy91 commented 3 months ago

This is the answer

You can check the defaultTargetPlatform from Flutter and just wrap that code in an if block.

We've been doing this for a long time in one of our apps that's running on mobile and desktop and it has worked flawlessly.