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. 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 solution 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 a 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 an event to the flutter side. Unlike
method channelthat can only receive one event, the receiver using
event channelcan receive multiple events until canceling the subscription.