[go: nahoru, domu]

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

Add more information about developing desktop plugins #7164

Open
GroovinChip opened this issue May 19, 2022 · 2 comments
Open

Add more information about developing desktop plugins #7164

GroovinChip opened this issue May 19, 2022 · 2 comments
Labels
d.enhancement Improves docs with specific ask dev.integration Relates to platform integration dev.plugin Relates to Flutter plugins e3-weeks Effort: < 4 weeks lang.native-code Involves Swift, ObjC, Java, or Kotlin code for mobile apps p2-medium Necessary but not urgent concern. Resolve when possible. t.desktop Relates to desktop compatibility of an app

Comments

@GroovinChip
Copy link

What information is missing?

The Developing Packages & Plugins document should go into more detail about writing plugins for desktop platforms. As a desktop plugin author myself, I have struggled mightily with the nuances of writing a plugin in Swift for macOS, C/C++ for Windows, and C/C++ for Linux (which seems to be different than the C/C++ for Windows). Doing something as simple as reading PlatformChannel arguments required a frustrating level of researching. The API docs for the native Flutter platform code (things like FlutterResult, etc etc) are super hard to find and are also poorly documented. The only existing codelab for desktop provides zero explanation for the step that covers writing a plugin.

Basically, there is little to no documentation available on this subject as it relates to desktop. Given that all three desktop platforms are now officially stable, I believe it is past time for in-depth documentation to be provided by Flutter on writing desktop plugin.

A section of this document that might be good for (some, if not all of) these details is Step 2: Implement the package. Alternatively, it could be its own section, or even its own page.

Here are some of the topics I have struggled with in the past. All code snippets are from a real plugin I'm working on to generate thumbnails from videos:

  • How to properly read, store, and handle PlatformChannel arguments
    • Swift (macOS)
      • Reading Map arguments
        if let arguments = call.arguments as? Dictionary<String, Any>,
          let path = arguments["filePath"] as? String,
          let position = arguments["position"] as? Int64 {
            // do something
          }
      • Returning Map arguments back to Flutter
        let resultMap = ["data": base64String, "videoLength": durationTime] as [String : Any]
        result(resultMap)
    • C/C++ (Windows)
      • Reading Map arguments
        const auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
        auto* path = std::get_if<std::string>(&(arguments->find(flutter::EncodableValue("filePath"))->second));
        auto* position = std::get_if<double>(&(arguments->find(flutter::EncodableValue("position"))->second));
      • Returning Map arguments back to Flutter
        result->Success(flutter::EncodableMap{
            { "width" , static_cast<int64_t>(width)  },
            { "height", static_cast<int64_t>(height) },
            { "depth" , static_cast<int64_t>(depth)  },
            { "videoDuration" , static_cast<double>(((double)duration) / 10000000.0 )  },
            { "data"  , pixels },
          });
    • C/C++ (Linux)
      • Reading Map arguments (real code sample):
        if (strcmp(method, "generateThumbnail") == 0) {
          FlValue *args = fl_method_call_get_args(method_call);
          FlValue *filePath = fl_value_lookup_string(args, "filePath");
          FlValue *position = fl_value_lookup_string(args, "position");
        }
  • Properly listening to EventChannels (not related to the thumbnail plugin)
    • Some third-party content can be found on this, but not for desktop specifically. There is open source code available to read and try to emulate, but it was still a difficult process and it would be nice if there were some official guides on this. I've also only done this for macOS so far, so I can't speak to the difficulty/nuance of doing it on Windows & Linux.
  • How to use external libraries
    • macOS
      • I haven't needed to do this yet so I'm unclear on what's required or how difficult it is
    • Windows
      • This plugin required use of the Microsoft MediaFoundation library. Linking that library to the windows runner was infuriatingly difficult, and it took several days, a lot of research, and help from several people to get this working. It required creating a dedicated cmake file to find the library and modifying CMakeLists.txt, and the nuances of both of those steps work were hard to figure out. Documentation from Flutter on this would have been quite helpful.
    • Linux
      • I have started on the Linux variant of the afore-mentioned plugin, which will require the ffmpeg library, but stopped because its such an enormous headache. Again, documentation on this would be super helpful.

I'm sure that there are many more nuances related to writing desktop plugins for Flutter that people struggle with.

How would you like us to fix this problem?

Please consider writing in-depth documentation on this subject. I'd be happy to collaborate on this, if desired.

@danagbemava-nc danagbemava-nc added st.triage.triage-team Triage team reviewing and categorizing the issue d.enhancement Improves docs with specific ask p2-medium Necessary but not urgent concern. Resolve when possible. e3-weeks Effort: < 4 weeks and removed st.triage.triage-team Triage team reviewing and categorizing the issue labels May 20, 2022
@timsneath
Copy link
Contributor

Yup, that's a good call-out. #7123 is related...

On the Windows side, https://pub.dev/packages/win32 gets us ever closer to supporting everything you might do with a plugin using just Dart code in a package. It provides solid wrappers for Win32 and COM, we're continuing to develop WinRT support.

@Chappie74
Copy link

I support this so much. I've been struggling so hard. Heck that's how I ended up here lol. I've managed to figure the basic things out using the url_launcher and path_provider packages. Currently struggling with figuring out how, on the c++ side, do I access the data passed from the dart side.

Thanks for this basic guide. Helps me out a ton.

@atsansone atsansone added dev.integration Relates to platform integration lang.native-code Involves Swift, ObjC, Java, or Kotlin code for mobile apps dev.plugin Relates to Flutter plugins t.desktop Relates to desktop compatibility of an app ltw-triage labels Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
d.enhancement Improves docs with specific ask dev.integration Relates to platform integration dev.plugin Relates to Flutter plugins e3-weeks Effort: < 4 weeks lang.native-code Involves Swift, ObjC, Java, or Kotlin code for mobile apps p2-medium Necessary but not urgent concern. Resolve when possible. t.desktop Relates to desktop compatibility of an app
Projects
None yet
Development

No branches or pull requests

6 participants