macosui / macos_window_utils.dart

macos_window_utils is a Flutter package that provides a set of methods for modifying the NSWindow of a Flutter application on macOS.
https://pub.dev/packages/macos_window_utils
MIT License
49 stars 9 forks source link

macos_window_utils/MainFlutterWindowManipulator.swift:370: Fatal error: Unexpectedly found nil while unwrapping an Optional value #21

Closed lucasjinreal closed 1 year ago

lucasjinreal commented 1 year ago
macos_window_utils/MainFlutterWindowManipulator.swift:370: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Got this when running old code.

Here is the setup in main.swift:

import Cocoa
import FlutterMacOS

class MainFlutterWindow: NSWindow {
  override func awakeFromNib() {
    let flutterViewController = FlutterViewController.init()
    let windowFrame = self.frame
    self.contentViewController = flutterViewController
    self.setFrame(windowFrame, display: true)

    RegisterGeneratedPlugins(registry: flutterViewController)

    super.awakeFromNib()
  }
}
Adrian-Samoticha commented 1 year ago

If you mean the MainFlutterWindow.swift file, it needs to look like this:

import Cocoa
import FlutterMacOS
import macos_window_utils

class MainFlutterWindow: NSWindow {
  override func awakeFromNib() {
    let windowFrame = self.frame
    let macOSWindowUtilsViewController = MacOSWindowUtilsViewController()
    self.contentViewController = macOSWindowUtilsViewController
    self.setFrame(windowFrame, display: true)

    /* Initialize the macos_window_utils plugin */
    MainFlutterWindowManipulator.start(mainFlutterWindow: self)

    RegisterGeneratedPlugins(registry: macOSWindowUtilsViewController.flutterViewController)

    super.awakeFromNib()
  }
}