flutter create --template=package package_name
src: Private code directory
package.dart: // Main file, the file name must equals to the package name
Don’t write any useful code in the
package_name.dart, this file is just used to import the files you want to expose in
flutter create --org com.example --template=plugin --platforms=android,ios -i swift plugin_name
--org: Your organization host.
--platforms: The platforms this plugin supported.
--iSpecify ios development language (oc/swift)
- Open the plugin directory you can find a
Runner.xcworkspacefile, open it.
- The plugin code is in the path
- If you want to test the plugin code, you have two ways. The first you can directly write test code in the
Runnertarget. Another better way is creating a
- There are some problems you will get, you cannot
import plugin_nameto test its code.
- I have a solve is appending pods dependence for the unit test target:
target 'pluginName_exampleTests' do
- Test code examples:
- Method Channel
- You can send an action from flutter to native or reversing, and then you can asynchronously get a result from the other side.
- Event Channel
- Can only send message from native to flutter
- Like an
event stream, you can register the event channel in flutter to handle events, the native side will get a
sinkused to send event to flutter side. Not like
method channelthat can only receive one event, the receiver using
event channelcan receive multiple events until canceling the subscription.