Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create a hover compatible plugin

Pierre Champion | Drakirus edited this pageMar 21, 2020 ·11 revisions

Add go-flutter support to a flutter plugin

In this tutorial will get the most simple platform plugin up and running using go-flutter.

TL;DR:

flutter create --template=plugin test_hovercd test_hoverhover init-plugin github.com/my-organization/test_hovercd exampleflutter build bundlehover inithover plugins getyes| hover run

After runningflutter create --org com.example --template=plugin test_hover.
You have a newly created flutter plugin project in thetest_hover/ folder with the specialized android/ios code related to the plugin.

Initialize a go-flutter plugin

To add support for go-flutter, you need to runhover init-plugin github.com/my-organization/test_hover.
The Github VCS URL is crucial, as this is where your plugin will be published and fetch by the golang tool-chain.

Once initialized the directory of your plugin should look something like this:

$ lsandroid  CHANGELOG.md  go  test_hover.iml  ios  lib  LICENSE  pubspec.yaml  README.md  test

Under the go directory, you will find the following hover created files:

$ ls godlib  go.mod  go.sum  import.go.tmpl  plugin.go  README.md

Each file have a specialized purpose:

  • plugin.go is where your platform plugin code lives.
  • import.go.tmpl is used by hover to import your plugin (hover plugins get).

    ⚠️ This file will be copied to the flutter project and is responsible for importing the plugin.
    Plugin makers are encouraged to tweak this file to their needs!

  • go.mod andgo.sum are used by the golang tool-chain for versioning.
    More information about 'go modules' is available on thegolang wiki.
  • Thedlib folder is used for the plugins which useCGO dynamic libraries.

Test the plugin

Once generated, you can test the plugin in theexample directory:

  • cd example to go to the flutter app that depends on the plugin, and illustrates how to use it.
  • hover init to initialize go-flutter.
  • hover run to compile and run your application.
    • At that point, the application display"Running on: Unknown".
      The go plugin generated byhover init-plugin XX isn't added to the project.
  • hover plugins get to import the plugin.
    • hover support two types of plugin, 'hosted' one and 'path' one declared respectively inpubspec.yaml as:
      # hosted plugintest_hover:^M.m.p
      and
      # path plugintest_hover:path:../
  • hover run, the application should display"Running on: go-flutter vX.X.X".

Everything is working! You can go and modify the content oflib/test_hover.dart andgo/plugin.go.

Note: multipleshover plugins commands are available,read more here.

Publish your plugin

Once you are happy with your plugin, you can deploy it as a hosted one.

To do so, go to the root of your plugin (cd .. if you where in the exampledirectory), and runhover publish-plugin.

To successfully publish your plugin, you need to create a git tag.
To automate this process,hover publish-plugin can be used,publish-pluginensure that yourgo directory is clean and that your remote git URL matches theVSC URL defined ingo/go.mod.

Note

The rule of thumb to use golang module in the context of go-flutter is:

  • The VCS URL should always point to a directory containing a go.mod file.
  • The tag name of the git tag should be 'go/0.0.1' with '0.0.1' the stringcorresponding to theversion number in thepubspec.yaml file.And 'go' the path from the root of your repo to the go.mod file.
    • For example, in thesqfliteplugin, the tag should besqflite/go/1.1.7+2.
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp