Effective code in your Flutter app from the beginning

Effective code in your Flutter app from the beginning

One of the features of Flutter is a possibility to create apps in record time. However, it is very important to write Dart code properly and to use the best practices, Effective Dart, from the beginning. There are some good tools and packages that help you to apply best practices quickly.

One of the features of Flutter is a possibility to create apps in record time. However, it is very important to write Dart code properly and to use the best practices, Effective Dart, from the beginning. There are some good tools and packages that help you to apply best practices quickly.

Default IDE static analysis

Dart has a static analysis tool. Static analysis allows you to find problems before executing a single line of code. It’s a great tool used to find possible bugs and ensure that code conforms to style guidelines. When you use IDE to develop an app, Flutter tool analyzes the project’s Dart code and keeps you in a safe place. For example, when you define FloatingActionButton and forget to implement onPressed, then IDE warns that the param onPressed is required.

IDE static analysis

You can also run flutter analyzein your terminal to check your code. This tool is a wrapper around the dartanalyzer tool. All default lint rules that are used for Flutter by IDE are listed here.

Part of IDE’s analysis_options file

From the image above you can see that some of the lint options are commented out. But they might be useful for your project. To enable them you can create analysis options file in your project.

Analysis options file

For this, you need to place analysis_options.yaml at the root of the package, in the same directory as the pubspec.yaml file.

analysis_options.yaml at the root of the package

Here you can enable/disable linter rules, enable stricter type checks, exclude files for linter check and more. The full list of supported lint rules with documentation is always updated here_. Y_ou can copy-paste all of them in your analysis_options.yaml. Or you can have a look at the [*analysis_options.yaml](https://github.com/dart-lang/linter/blob/master/example/effective-dart.yaml "analysis_options.yaml*") with rules that are following the Effective Dart guide.

Pedantic package

If you don’t want to explore linter rules list for analysis_options.yaml and you’d like to start working on features as soon as possible you can give a try to pedantic package which is a good starting point that helps to write readable and effective Dart code. Documentation represents this package as default Google’s rules, that are used in their own Dart code. To use lint rules from this package, you need to add:

  • a dependency in your pubspec.yaml:
  • dev_dependencies: pedantic: ^1.4.0
  • one line of code in your analysis_options.yaml:
  • include: package:pedantic/analysis_options.yaml

Don’t forget to run flutter packages get to update dependencies. And now it is time to hack away!

P.S. When you have an asynchronous app, it is expected that all your Futures are awaited, so pedantic package has a lint rule unawaited_futures. But sometimes you have a case when a Future is not awaited intentionally. Therefore pedantic package provides a function

void unawaited(Future<void> future)

for silencing the rule. This function may be used to ignore a particular Future.

  • a dependency in your pubspec.yaml:
  • dev_dependencies:&nbsp;pedantic: ^1.4.0
  • one line of code in your analysis_options.yaml:
  • include: package:pedantic/analysis_options.yaml

flutter mobile-apps

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Google's Flutter 1.20 stable announced with new features - Navoki

Google has announced new flutter 1.20 stable with many improvements, and features, enabling flutter for Desktop and Web

Top 25 Flutter Mobile App Templates in 2020

Flutter has been booming worldwide from the past few years. While there are many popular mobile app development technologies out there, Flutter has managed to leave its mark in the mobile application development world. In this article, we’ve curated the best Flutter app templates available on the market as of July 2020.

How To Succeed In Mobile App Wireframe Design?

This article covers everything about mobile app wireframe design: what to do and what not, tools used in designing a mobile or web app wireframe, and more.

How much does it cost to make a Flutter app for your business?

Get a Free Quote on Android App Development, iPhone App Development, Ionic App Development, Video Development, ASO, SEO, Google Ads/Adwords, SEO for your app Idea.

Flutter – A Boon to Mobile App Developers

Flutter app development is in trend; ever since flutter - the mobile app development framework, has been helping app developers to build amazing applications.