In one of our previous blogs I explained how I wrote our icapps_translations plugin for Flutter with all the bells and whistles.

I explained to you that it is important to have a good foundation when starting with a new technology. You need to be ready for takeoff when clients ask for a new project. So after finishing our proof of concepts, I gathered all the information on how we should work with Flutter and what should be included in the template project. You can find the template I've built here. 

At icapps we have a couple of template projects to make sure we can start a new project without having to do the setup again every time. It took some time to get everything up and running but now we’re here...

 

What do we need?

A template project should contain all the main components for starting a new project. This is what we think should be included in every project.

  • Network Layer

  • Network logging

  • Json Parsing

  • Dependency Injection

  • Flavors (Alpha, Beta, Release)

  • Flavor Configs

  • Viewmodels

  • Repositories

  • Translations

  • Navigation

  • Linting

  • Theming

  • An example that binds everything together

 

Network layer

When building our proof of concept we used the simple HTTP library but we found that we needed to cancel our network calls sometimes. We also wanted a more reliable way for adding interceptors and implementing refresh tokens. That is where Dio comes into play. Dio is a powerful HTTP client for Dart that supports all of the above issues. It is also one of the top Dart packages on pub.dev.

 

Network Logging

Network logging is maybe one of the coolest parts of this blogpost. Nicola Verbeeck, one of our colleagues,  wrote a plugin for Android development called Niddler. It allows you to inspect your network traffic even after the calls have been finished. So let's say you had an unexpected behavior in your app, Niddler makes it possible to check what response you got from the API. 

This is very powerful because a lot of other network logging tools do not provide this functionality. During our proof of concept we felt the need for a Niddler plugin that worked with Flutter. But why stop there? Niddler should not only be available for Flutter, it could be available for Dart itself. Nicola wrote a version for Dart during our proof of concept to make sure we had the same tools available as we had during Android development. 

If you want to use this, please check out this awesome package at pub.dev -> https://pub.dev/packages/niddler_dart. The plugin for android studio is available for download in the plugins section in android studio itself, or here https://plugins.jetbrains.com/plugin/10347-niddler

 

Json parsing

While working with network requests you will also need a JSON parser with it. When I started with Flutter one of the best resources available was the boring show. So when I started Flutter development I used built_value. This was fine for basic response parsing, but was terrible at parsing requests to a JSON format. 

We used it in our proof of concept as well and felt the limitations very quickly. So when I started on the Flutter Template itself I found that there was a much better package available that did everything (almost everything) what we needed. We could provide nullable and non nullable fields, add enums to our JSON objects and parse everything we needed. The only minor problem we’ve faced at this moment with the package is that it does not support nested fields.