General flutter plugin development info can be found at https://flutter.dev/docs/development/packages-and-plugins/developing-packages
IDE integration seems well supported in vscode and android studio, but android studio is recommended setup.
The flutter and native code in this repo communicate by serializing responses to JSON strings.
In the future it may be valuable to take advantage of pigeon
for type safety; however, since it is in pre-release we are not currently utilizing it.
The current plugin takes advantage of annotations,
to generate JSON parsers automatically. The models live in tozny_models.dart and
the generated files are created by running flutter pub run build_runner build
. If this command fails, run flutter clean
to clear the build cache then re-run the previous command. This will delete the build/
and .dart_tools/
directories before the next build.
When developing native portions of the plugin a full re-compile is needed, hot restarts don't reflect current state.
With the introduction of the iOS plugin, Android Studio cannot automatically index the Android plugin when opening the root of the directory. To open the Android plugin in Android Studio, choose the Open an Existing Project
option and open the android/
folder in flutter_plugin/example/
.
To run the example application, choose the app
configuration at the top menu bar, open a device simulator (Tools -> AVD Manager
), and then choose either the Run app
or Debug app
buttons next to the Available devices
dropdown menu.
Dependencies may potentiatially be out of date. In order to identify any out of date dependencies run flutter pub outdated
in the directory that contains pubspec.yaml
. If there are outdated direct dependencies listed in the command's output their respective versions should be updated in pubspec.yaml
.
Run flutter pub get
to update the package dependencies to the new versions. pubspec.lock
will be updated to save the new concrete package versions
Adding support for different platforms may be wanted or necessary, so below is an example of adding support for iOS to the Tozny Flutter plugin. Run this command at the top level directory of the repository. Tozny plugin has partial support for iOS, so the below command needs not be run.
flutter create --template=plugin --platforms=ios --ios-language=swift --org=com.tozny .
The flutter create
commmand defaults to using the application template, so --template
must be set to plugin
. The platform the plugin code is autogenerated for is defined using the --platforms
option. Some platforms may have different language options (e.g. swift
and objc
for the ios
platform), so specifying the language may be required. The --org
option will be used for package naming in Java and as a prefix in iOS's bundle identifier.
The repository in which the platform support is generated for needs to have a Dart package compliant name. Specifically, package names should be lowercase with words separated by underscores.
The flutter create
command will complain if the repository name does not adhere to this convention, so make sure to rename the repository's name if necessary.
At the time of this writing the Tozny plugin's repository is named such that it will encounter this problem.
The Tozny iOS plugin requires Xcode and Cocoapods installed in order to be built.
Before opening the project, make sure that all necessary project dependencies and pods are installed by running the commands flutter pub get
from the root of the repository and pod install
from the example/ios/
directory. This installs the dependencies and pods found in the project's Podfile and each module's .podspec
file.
Run pod update
in example/ios/
after the first time pod install
ran. This is not necessary each time as it only updates pods in the Podfile to the latest version and pre-loads some Pods (e.g. E3db
) into the project's workspace.
Now, before opening the project in Xcode, build the project by running flutter build --no-codesign
in the example/ios/
directory. The --no-codesign
option should be removed if building for deployment.
When building finishes, open the Runner.xcworkspace
file in the example/ios/
directory in XCode. In order to test the application, Xcode's Build and run current scheme
button (a triangle in the top left) will open a simular and run the application. Ensure that recent iPhone is chosen as the scheme to the be run (development so far has used an iPhone 12 Max Pro device).
Swift files for the plugin can be found via Xcode's navigator menu in the following directory: Pod/Development Pods/plugin_tozny/../../example/ios/.symlinks/plugins/plugin_tozny/ios/Classes
.
In the iOS plugin, a specific commit for dependencies can be chosen by adding commit => 'commit name'
after a pod
in the Podfile
, e.g.
pod "E3db", :git => 'https://github.com/tozny/e3db-swift', commit => 'asdf'
Most common issues that might arise when developing the iOS plugin can be resolved by one of the following steps:
- If Xcode complains that modules are not able to be found, close XCode and run
pod install
in theexample/ios/
directory. This command installs the pods in the project's PodFile, and must be run every time there are added or removed pods from the PodFile.- Xcode must be restarted each time this is done in order to reflect the new changes in the workspace.
- Another possible solution to a missing module error is that the module may need to be added to the target's
.podspec
file (e.g. inplugin_tozny.podspec
for theplugin_tozny
target) or aPodfile
. Similarly to the steps above, once edits are made runpod install
and restart Xcode. - If it is the case that in Xcode's navigator menu neither the Runner or Pod targets show the Swift files for the plugin, make sure that when opening the project in Xcode the
Runner.xcworkspace
file that is opened and notRunner.xcodeproj
. -
An error occurred while processing the post-install hook of the Podfile. undefined method `each_child' for #<Dir:0x00007fcf7f022d98> Did you mean? each_slice
- If errors such as the above occur during execution of the
pod install
command, it likely means that your Ruby install is out of date.
- If errors such as the above occur during execution of the
- Checkout code from branch
- Write code, test code
- Update plugin version in
pubspec.yaml
file,CHANGELOG.md
andREADME.md
as needed - Before committing changes for review, run
flutter pub publish --dry-run
- Commit & PR changes
- Once PR is approved, merge into trunk
- Check out trunk, push a git tag matching the version tag in
pubspec.yaml
- Run
flutter pub publish