website icon indicating copy to clipboard operation
website copied to clipboard

Improve documentation on 'Developing packages, adding a windows to plugin package, pubspec.yaml'

Open benthillerkus opened this issue 2 years ago • 0 comments

Page URL

https://docs.flutter.dev/packages-and-plugins/developing-packages/

Page source

https://github.com/flutter/website/tree/main/src/packages-and-plugins/developing-packages.md

Describe the problem

After running flutter create --template=plugin --platforms=windows users have to manually add them the new plugin entry point classes to the pubspec.yaml. From reading the documentation, the CLI messages and the compiler errors when doing it wrong, it was very unclear to me what would be expected entry value for Windows.

Considering how it looks on macOS and web, I tried

  plugin:
    platforms:
    # This plugin project was generated without specifying any
    # platforms with the `--platform` argument. Add platforms following the instruction here:
    # https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms
    # -------------------
      macos:
        pluginClass: MillimetersPlugin
      windows:
        pluginClass: MillimetersPlugin
      web:
        pluginClass: MillimetersWeb
        fileName: millimeters_web.dart

but this is wrong and will end up with MSVC not being able to find millimeters_plugin.h (millimeters is the package name I chose). I really couldn't figure out what was causing this, until I ended up creating an entirely new project with Windows support.

Turns out the correct value would be:

windows:
  pluginClass: MillimetersPluginCApi
  

which I guess might be logical, when knowing how the whole CMake magic works in the background, just documenting this better would make it much more accessible.

Expected fix

  1. Inside the article show example pubspec.yamls for all platforms.
  2. Amend the prompt messages inside the pubspec.yaml, the console, and the README to be more specific on how to add the platforms to the pubspec.
  3. When using flutter create -t plugin for scaffolding projects, fill out the entire
plugin:
  platforms:
    ----

tree and comment out every platform that hasn't been generated.

Additional context

No response

benthillerkus avatar Jul 22 '23 02:07 benthillerkus