I am new to flutter development and currently developing 4 apps at the same time. So I want to share codes between these apps by creating plugin or package. But I don't understand what to choose between package or plugin for my case.
I will be writing only dart codes in this sharable codes but I will be using other plugins from pub.dev which have native codes in them like Kotlin and Swift example flutter_contacts which have java and swift codes in it.
So what should I choose between plugin and package for this scenario.
TLDR
plugin= some functionality of tool. Package= something which allows us to develop new thing.
Flutter provides a mechanism for authoring plugins that allows you to communicate with platform-specific code and also allows you to publish your plugins on pub. dev so that others can use them. In this codelab, you'll learn how to author your own plugins for iOS and Android.
A package is a namespace that contains a group of similar types of classes, interfaces, and sub-packages. We can think of packages as similar to different folders on our computers where we might keep movies in one folder, images in another folder, software in another folder, etc.
A "package" contains only Dart code.
A "plugin" contains both Dart and Native code (kotlin/js/swift/...)
A package can use plugins if it wants to. It will still qualify as a package.
Based upon reading this Flutter documentation: Developing packages and plugins, I will be sharing my views to make you clear on the package and plugin difference
.
First of all welcome to the
Flutter Community
, great platform to build best applications for yourWeb/Android/iOS
with a single code base
Now, let us try clearing our doubt on the aforementioned topic.
What is a Plugin?
Packages enable the creation of modular code that can be shared easily. A minimal package consists of the following
Now, the best part, which will clear your doubt:
Plugins
are nothing but a part of theFlutter Packages
which is platofrm dependent
Types of Packages:
Android (using Kotlin or Java)
, iOS (using Swift or Objective-C)
, web
, macOS
, Windows
, or Linux
, or any combination thereof. A concrete example is the url_launcher plugin package. To see how to use the url_launcher package, and how it was extended to implement support for web, see the Medium article by Harry Terkelsen
If that still doesn't clarifies your doubt, you must look at the first link Developing packages and plugins I gave it for you. It will definitely give you the clarity.
In short: Native related developments.
Flutter plugin is the wrapper of the native code like android( Kotlin or java) and iOS(swift or objective c). ... Flutter can do anything that a native application can through the use of Platform Channels and Message Passing. Flutter instructs the native iOS/Android code to perform an action and returns the result to Dart.
In short: Make the development faster by using code from util libraries.
Flutter supports using shared packages contributed by other developers to the Flutter and Dart ecosystems. This allows quickly building an app without having to develop everything from scratch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With