-
Notifications
You must be signed in to change notification settings - Fork 282
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_hover cd test_hover hover init-plugin github.com/my-organization/test_hover cd example flutter build bundle hover init hover plugins get yes | hover run
After running flutter create --org com.example --template=plugin test_hover
.
You have a newly created flutter plugin project in the test_hover/
folder with the specialized android/ios code related to the plugin.
To add support for go-flutter, you need to run hover 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:
$ ls
android 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 go
dlib 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 the golang wiki. - The
dlib
folder is used for the plugins which useCGO
dynamic libraries.
Once generated, you can test the plugin in the example
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.
- At that point, the application display
-
hover plugins get
to import the plugin.- hover support two types of plugin, 'hosted' one and 'path' one declared respectively in
pubspec.yaml
as:and# hosted plugin test_hover: ^M.m.p
# path plugin test_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 of lib/test_hover.dart
and go/plugin.go
.
Note: multiples
hover plugins
commands 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 example
directory), and run hover 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-plugin
ensure that your go
directory is clean and that your remote git URL matches the
VSC URL defined in go/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 in https://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 string corresponding to the
version
number in thepubspec.yaml
file. And 'go' the path from the root of your repo to the go.mod file.
- For example, in the sqflite plugin, the tag should be
sqflite/go/1.1.7+2
.