Nux
Nux

Reputation: 7078

what is the difference between flutter package and flutter plugin

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

Upvotes: 47

Views: 25422

Answers (4)

Saurabh Kumar
Saurabh Kumar

Reputation: 2783

A plugin is a special kind of package that involves native Kotlin/Java(for Android) or swift/Objective-C(for iOS) code. A package contains only dart code.

You need a plugin when you need to communicate with native OS.

Some examples of packages and plugins are as follow:

Package:

  • http: A package that provides an easy-to-use API for making HTTP requests from a Flutter app.

  • shared_preferences: A package that provides a simple way to store and retrieve key-value pairs in persistent storage.

  • intl: A package that provides internationalization and localization support for Flutter apps.

Plugin:

  • camera: A plugin that provides access to the device's camera and allows taking pictures and recording videos.
  • firebase_messaging: A plugin that allows Flutter apps to receive and handle push notifications using Firebase Cloud Messaging.
  • google_maps_flutter: A plugin that provides a Flutter widget for displaying interactive maps using the Google Maps API.

From the examples it should be clear why plugin require native code.

Upvotes: 15

Rémi Rousselet
Rémi Rousselet

Reputation: 277067

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.

Upvotes: 114

Alok
Alok

Reputation: 8998

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.

Upvotes: 13

Asmoun
Asmoun

Reputation: 1747

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.

Upvotes: 19

Related Questions