- Notifications
You must be signed in to change notification settings - Fork282
Create a hover compatible 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.
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 testUnder the go directory, you will find the following hover created files:
$ ls godlib go.mod go.sum import.go.tmpl plugin.go README.mdEach file have a specialized purpose:
plugin.gois where your platform plugin code lives.import.go.tmplis 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.modandgo.sumare used by the golang tool-chain for versioning.
More information about 'go modules' is available on thegolang wiki.- The
dlibfolder is used for the plugins which useCGOdynamic libraries.
Once generated, you can test the plugin in theexample directory:
cd exampleto go to the flutter app that depends on the plugin, and illustrates how to use it.hover initto initialize go-flutter.hover runto compile and run your application.- At that point, the application display
"Running on: Unknown".
The go plugin generated byhover init-plugin XXisn't added to the project.
- At that point, the application display
hover plugins getto import the plugin.- hover support two types of plugin, 'hosted' one and 'path' one declared respectively in
pubspec.yamlas:and# hosted plugintest_hover:^M.m.p
# path plugintest_hover:path:../
- hover support two types of plugin, 'hosted' one and 'path' one declared respectively in
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: multiples
hover pluginscommands are available,read more here.
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.
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.
- For example, if your go.mod defines a module at the'github.com/my-organization/test_hover/go' URL ('go' is appended by hover),then a go.mod file is expected to be found inhttps://github.com/my-organization/test_hover/blob/master/go/go.mod
- The tag name of the git tag should be 'go/0.0.1' with '0.0.1' the stringcorresponding to the
versionnumber in thepubspec.yamlfile.And 'go' the path from the root of your repo to the go.mod file.
- For example, in thesqfliteplugin, the tag should be
sqflite/go/1.1.7+2.