Top 5 dev_dependencies Packages in Flutter

I hope you are doing well, in this article I will present some of the most useful dev_dependencies. But before we move on let’s first figure out why it is called dev_dependencies and what the actual difference is between dependency and dev dependency.

when you open a pubspec.yaml file you will find two kinds of dependencies first is the dependency and the other is the dev_dependency. Let’s first understand the difference between dependencies and dev_dependency.

Dependencies are libraries that a project requires to function properly. In other words, that effect will be directly applied to your main work. but a dev_dependency is a dependency that is not available for code in the resulting application, but only for tests, examples, tools, or to add executable tools such as code generation tools to a project.

During development and compile time, dev_dependencies are required. Include packages you will use during development or bundle building in dev_dependencies.

So, let’s see the most useful dev_dependency that helps us a lot.

flutter_lints (It encourages us to follow good coding practices)

It contains a list of lints for Flutter apps, packages, and plugins that encourage good coding practices.

Dart analyzers detect lints by statically checking dart code. Most Dart-enabled IDEs present the issues identified by the analyzer in their user interfaces. Running flutter analysis manually can also invoke the analyzer.

Additionally, projects created with Flutter version 2.5 or newer are already enabled to use the latest set of recommended lints. The instructions in this guide can be used to upgrade projects created before that version to it.

mockito (This allows you to create Mock Dependencies between classes while testing your code.)

There are times when unit tests depend on classes that fetch data from live web services or databases. A few reasons make this inconvenient:

  • The execution of tests is slowed down when live services or databases are called.
  • If an unexpected result is returned by a web service or database, a passing test may fail. The term “flaky test” refers to this situation.
  • By using a live web service or database, it is difficult to test all possible success and failure scenarios.

By doing this, you do not need to use live services or databases, but rather “mock” them instead. It is possible to simulate a live web service or database using mocks and return specific results depending on the situation.

It is possible to mock dependencies in general by using an alternative implementation of a class. If you want to implement these alternatives manually, you can do so or you can use the Mockito package.

The following steps show you how to use the Mockito package to mock:

  1. Add the dependencies to the package.
  2. Defining a test function is the first step.
  3. Prepare a test file that includes a mock http.Client.
  4. Test each condition by identifying it and writing a test for it.
  5. The tests should be run.

json_serializable (With this, Dart classes can be annotated in order to generate code for converting from and to JSON automatically.)

Using JSON serialization with code generation means allowing an external library to generate the encoding boilerplate on your behalf. In the first step, you create a file watcher to generate code from the model classes. There are libraries for this purpose, such as json_serializable and built_value.

build_runner (This package gives you a concrete way to generate files with Dart code, without having to use any tools like pub.)

With build_runner, you can generate files, test generated files, or serve both sources and generated files simultaneously. You can find more information about using build_runner on this page, which includes links to more information. If you want a detailed explanation of how to use build_runner with a specific package, check out its documentation.

Using the build_runner commands, you can build packages that generate output files from input files using the Dart build system. There are two packages that define builders that generate Dart code, json_serializable, and built_value_generator.

flutter_gen (This allows you to generate codes for your assets, fonts, colors, and localizations.)

With the flutter_gen, you can generate assets, fonts, colors, etc. without using any string-based APIs.

An image format supported by flutter_gen is used to generate the Image class. Here are some examples of assets/images/chip results.

You can easily use FlutterGen by following these steps:

  1. In your pubspec.yaml, you declare assets. The yaml file can be created normally; no further configuration is necessary.
  2. The Dart files will then be generated under the lib/gen directory by default by flutter_gen.
  3. Using the generated classes, you can then load your assets.

So that’s all the information, that I want to describe in short, all are perfect if you deeply understand as per your usage. I took it from many websites as some research if you find out any wrong info or miscorrected, please point out or comment below.

if you got something wrong? Mention it in the comments. I would love to improve.
I am Shirsh Shukla. A creative Developer and a Technology lover. You can find me on LinkedIn or maybe follow me on Twitter or just walk over my portfolio for more details.

Have a nice day!🙂

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shirsh Shukla

Shirsh Shukla

703 Followers

Mobile Application Developer | GDG Speaker | Technical Blogger at medium | community member at StackOverflow | Organizer @FlutterIndore