Introduction
In the modern world, the demand for developers is on the rise. Still, there are many developers available, but only some are successful and have high-paying jobs, so what is that? Suppose if two developers still have the same knowledge, one has a better life than the other one?
The answer is that only knowing the language or framework and writing code is insufficient for a developer. He has to write the optimized code that is easy to understand and has a short length and must use all the available technologies that make them user and beginner developer-friendly.
The same holds while using flutter, as you can reduce code size by using packages or plugins. We will learn about plugins in flutter while moving further in the blog. So let’s move on with our topic without wasting any further time.
Flutter Packages and their Types
A package is a collection of several groups that contains similar types of interfaces, classes, and sub-packages. Generally, you can relate the package to your computer's local storage. On your computer, you keep all your movies in one folder, software in one folder, and documents in another; similarly, packages keep the things with similar properties and features together.
In flutter, we use a dart to share and organize a set of functionality through a package. Flutter has a benefit in terms of packages as it supports shared packages, which other developers share in the Dart and Flutter Ecosystem. The packages are used to create an app. With the help of these packages, we can create an app from scratch.
The general structure of the package is explained below:
- lib/src/*: It has private dart files.
- lib/my_demo_package.dart: It is the main dart file and can be imported into the application as shown below:
import 'package:my_demo_package/my_demo_package.dart'
- You can import any other dart file in your code as shown below:
export src/my_code.dart
- lib/*: This file contains all the public code in the package. We can use and access the file as shown below:
import 'package:mydemo_package/sub_folder/custom_file.dart'
- Pubspec.yaml: This file has the same specifications as that of the application. We will be using this file a lot during our work with flutter. This file contains project dependencies and general project settings like description, name, and project assets.
Types of Packages
Based on the functionality, we can divide packages into mainly three types, and we will discuss all three of them here:
- Dart Package: It can be understood as a general package that can be used in both mobile and web environments, and it is written in dart language. It slightly depends on the flutter framework as it contains some flutter-specific functionalities such as the fluro package.
- Flutter Package: It can be understood as generic dart code that can be only used in the mobile environment and depends on the flutter framework.
- Flutter Plugin: It can be understood as generic code that depends on the underlying platform code and the flutter framework. Example Camera is a plugin device but also depends on the flutter framework.