skip to Main Content

I want to execute a Go script within Flutter. Is there any possible way to do this and send data to a BMS device? Can I achieve this with Flutter?

"Can I use MethodChannels to execute the Go script? Will it work?
Otherwise I’ll havhe to implement the whole script into dart.

2

Answers


  1. when I wanted to do this with another language (rust),
    I found this article interesting

    basically using the dart:ffi package
    and you need to have some proficiency creating libraries with the go language

    Login or Signup to reply.
  2. Yes, you can execute a Go script within Flutter using platform channels, specifically MethodChannels. MethodChannels allow communication between Flutter and platform-specific code (such as Java/Kotlin for Android or Objective-C/Swift for iOS). Here’s an outline of how you can achieve this:

    • 1. Create a Go Executable: First, compile your Go script into an executable file that can run independently.

    • 2. Flutter Platform Channel: In your Flutter app, set up a MethodChannel to communicate with the native platform (Android/iOS).

    • 3. Native Bridge: Write platform-specific code (Java/Kotlin or Objective-C/Swift) to call the Go executable using Process or similar
      methods. Pass data between Flutter and the Go executable through this
      bridge.

    • 4. Send Data to BMS Device: Once the Go script is executed and data is processed, use platform-specific code to send data to the BMS
      (Building Management System) device using appropriate protocols or
      APIs.

    Regarding MethodChannels specifically:

    Can MethodChannels execute the Go script?

    No, MethodChannels are used for communication between Flutter and native platform code. You’ll use MethodChannels to trigger the execution of the Go script through platform-specific code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search