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 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.

Useful links:

  • 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

ECommerce Mobile App Development | Ecommerce Mobile App Development Services

We are leading ecommerce mobile application development company. Hire our ecommerce mobile app developer for your custom Ecommerce project at competitive rates. **Know about [Top ECommerce Mobile App Development...

We are leading ecommerce mobile application development company. Hire our ecommerce mobile app developer for your custom Ecommerce project at competitive rates.

Know about Top ECommerce Mobile App Development Company

ECommerce Mobile App Development Company in England

ECommerce Mobile App Development Company in England

At [**WebClues Global**](https://www.webcluesglobal.com/ "WebClues Global") we have been working on eCommerce apps for the last 7+ years and have built systems which are secure, reliable and easy to use. We have people who have good knowledge on a...

At WebClues Global we have been working on eCommerce apps for the last 7+ years and have built systems which are secure, reliable and easy to use. We have people who have good knowledge on a wide variety of ecommerce technologies – Magento eCommerce, WooCommerce, Shopify, Drupal Commerce, OpenCart, BigCommerce, Joomla , Prestashop, NopCommerce.

As a top ECommerce Mobile App Development Company in England, We have been in the business of software develop ment for 7+ years and we are a specialist in Team Software Development by following Agile Methods. We provide a range of services on eCommerce app development with the support of our deep web application development and mobile app development expertise.

Mobile App Development Company in USA

Mobile App Development Company in USA

**How [Mobile App Development Company in the USA](https://www.dataeximit.com/mobile-app-development-service/ "Mobile App Development Company in the USA"), can breathe life into Your Amazing Ideas?** Today’s Mobile world mobile apps become one of...

How Mobile App Development Company in the USA, can breathe life into Your Amazing Ideas?

Today’s Mobile world mobile apps become one of the important factors in each and every business whether it may be a product based company or a service-based company.

Data EximIT has a strong team of mobile app developers & programmers who have the qualifications and experience in developing apps across several platforms, including iOS, Android, and PhoneGap and. We give our clients complete flexibility with respect to cutting short or extending projects after the minimum term is complete.

Our Mobile App Development Services Are...

  • Android Application Development
  • iOS Application Development
  • Responsive Web Applications
  • Hybrid Mobile Application Development
  • Xamarin Application Development
  • Mobile UI/UX Design

Contact Our Experts For More Information