Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between flutter package and flutter plugin

Tags:

flutter

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

  • Can a package use plugins in it and still be a package?
like image 784
Nux Avatar asked Jul 29 '20 12:07

Nux


People also ask

What is the difference between package and plugin?

plugin= some functionality of tool. Package= something which allows us to develop new thing.

What is Flutter plugin?

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.

What is a Flutter package?

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.


3 Answers

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.

like image 159
Rémi Rousselet Avatar answered Oct 01 '22 02:10

Rémi Rousselet


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 your Web/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 the Flutter Packages which is platofrm dependent

Types of Packages:

  • Dart Packages: General packages written in Dart, for example the path package. Some of these might contain Flutter specific functionality and thus have a dependency on the Flutter framework, restricting their use to Flutter only, for example the fluro package.
  • Plugin Packages: A specialized Dart package that contains an API written in Dart code combined with one or more platform-specific implementations. Plugin packages can be written for 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.

like image 35
Alok Avatar answered Oct 01 '22 01:10

Alok


Flutter plugins:

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.

Flutter packages or modules:

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.

like image 20
Asmoun Avatar answered Oct 01 '22 03:10

Asmoun