Flutter UI code tutorial: mastering Row and Column

Learning a new UI engine is always tricky. Thankfully, the Flutter team has highlighted the basic widgets. For this code tutorial, we will focus on Row and Column, which lay out a list of child widgets in the horizontal and vertical direction respectively.

First off, my favourite thing about them is that, even though you may mistake them for Android SDK’s LinearLayout at first, they are actually far more flexible, yet easy to understand.

To figure out how Row and Column work, we will start from 3 different mock-ups and lay them out using them. We will do this as part of an app with 3 screens (one screen per example).

For each example, we will have a rough sketch of what we want, with notes to describe how each part of the layout behaves. Why rough hand drawn sketches and not fancy mock ups done in Photoshop? Because I want to show you a simple process that you can apply to your own mock ups. Oh, and also because pen and paper is a very useful tool (see Tip 3 of 4 tips to boost your software development career).

A few basic rules to remember

The documentation is rich in explanations about how Flutter lays things out, but, when you’re starting out, this is a bit daunting. So, I’ve extracted a few basic Flutter UI rules that will allow you to build many layouts.
Continue reading “Flutter UI code tutorial: mastering Row and Column”

How to startActivityForResult in Flutter?

Most Android apps make use of startActivityForResult at one point or another. But, how do you do this in Flutter?

The official doc

The very helpful Flutter For Android Developers page on the official Flutter website demonstrates a way to do it using Navigator.of(context).pushNamed.

However, in the official doc about Navigation, using MaterialPageRoute is recommended for Material Design apps. So, how do you combine the two?

Adapting the official doc to using MaterialPageRoute

My first attempt provided a crash, as below.

Turned out it was due to using new MaterialPageRoute<Null>, which I had copied from the Navigation page. The solution: replace Null with dynamic.
Continue reading “How to startActivityForResult in Flutter?”

How to write an integration test in Flutter

We all know that no app is maintainable without tests. Indeed, strength of a framework is a function of how easy integration tests are to write and maintain. And I don’t say this lightly – I wrote Android integration tests for a 4.3 rated app with more than one million downloads before Espresso came along!

Flutter offers 3 types of tests: unit, widget, and integration tests. For this code tutorial, I will focus on integration tests – usually the most difficult to write, yet the most rewarding to have.
Continue reading “How to write an integration test in Flutter”

How to implement a GestureDetector in Flutter?

Flutter does provide common widgets handling tap, such as IconButton. But sometimes, you need to detect gestures on a custom view: here comes GestureDetector!

How to add a GestureDetector

To follow the code tutorial, create a new app as follows.

If you’re unsure how to set up a Flutter app, check out Getting started with Flutter official tutorial.

Continue reading “How to implement a GestureDetector in Flutter?”

How to scroll to a position in Flutter ListView?

Flutter ListView is very easy to use, and very versatile. As an Android developer used to creating Adapters for my RecyclerViews, I appreciate the simplicity of Flutter. However, one often used functionality is lacking, and it is smoothScrollToPosition(int position).

There is currently an open github issue  requesting this very feature.

In the meanwhile, for lists where all items have the same height, there is a trick you can use.
Continue reading “How to scroll to a position in Flutter ListView?”

How to increase your Android app ratings

Android app ratings and reviews: we love them, and we fear them. At times, it can feel that users only bother with them to complain. Sure, we like to hear about the issues in our apps so we can improve them, but a little love would be nice too!

There is a simple trick to increase your Android app ratings, but it needs to be deployed with care.

Is your app ready for higher ratings?

Overall, the foremost requirement to get higher ratings is to have a good app. If your app doesn’t do what users expect it to do, improve your app rather than obsess about your ratings.

So, before reading on, ask yourself: are you proud of your app?
Continue reading “How to increase your Android app ratings”

How to parse JSON in Dart / Flutter

JSON is a cornerstone in most Android apps, but how do you parse JSON in Dart and Flutter?

As mentioned in my “4 tips to boost your software development career” post, I’ve been experimenting with Flutter recently. Dart, the language used by Flutter, comes with a good library to parse JSON (dart:convert) but after having used gson for years in my Android apps, I had to relearn how to parse JSON.

If you Google gson for Dart , you will also find a library called dson. However, for this code tutorial, I’m focusing on using dart:convert.

To follow the code tutorial, create a new app as follows.

If you’re unsure how to set up a Flutter app, check out Getting started with Flutter official tutorial.

Continue reading “How to parse JSON in Dart / Flutter”

4 tips to boost your software development career

Software development is a fast-changing field. But, you, personally, do you write code now that you wouldn’t have written a year ago? If not, you may be missing out on a lot of career opportunities (as well as a lot of fun).

I’m NOT suggesting you do the tips below in your spare time. I don’t believe in the myth of “You need to have x personal coding projects to show your software development skills”. Indeed, I have a young family and I restrict my working hours (Sounds crazy? Read Why the CEO of Basecamp only allows employees to work 32 hours a week). You should try the tips below while working as you normally do.

Tip 1: Identify a software development task you don’t like (and do it for 30 minutes)

We all have tasks we don’t like doing. We know them, our colleagues know them, our employers know them (or soon will), and they are holding us back. Most often than not, it’s just a silly reluctance: yes, we may never love doing them, but there is no reason to let them stop us from progressing in our career.
Continue reading “4 tips to boost your software development career”

The analytics checklist: what to measure and look for

When you launch an app or update, you often hope to get new users and/or more revenue. Google Play Developer Console keeps track of those metrics for you, but whether you see numbers you like or dislike, you don’t know much about what drives them.

Analytics, which I’m using in the general sense of collecting data on usage and errors, can help you understand both the pain points and the users of your app, allowing you to focus on removing roadblocks and serving your users’ needs better. This will, in turn, increase your users’ satisfaction, leading to higher ratings and new users, as well as higher revenue per user.

Google Analytics, specifically, comes with an Android SDK and the web interface is already known to many business users, making it a great tool to implement your analytics strategy. There is a whole section on the android developer website taking you around its features. It’s a great product that gives you rich “out of the box” data on your users.

Putting aside the implementation details for a minute, let’s focus on what to measure and look for…

Identify functional problems

  • Crashes – If you don’t already, regularly check the reported Exceptions and ANRs in Google Play Developer Console.

  • Caught Exceptions – Some exceptions are expected but you should still know about them, because they may indicate a latent issue with your app.

  • Communication with servers – Background syncing is vital to delivering a fast, smooth, efficient app. How long do your server calls take? What percentage of your calls end in an IO Exception or a response time of more than 10 seconds? What percentage of your users are on wifi, 4G, 3G and 2G? How often do specific exceptions related to your local caching and server sync happen, for example SQLExceptions?

  • Location, location, location – For exceptions that you catch, do they happen specifically for a given time zone or language? Android is the most popular mobile platform in the world today so you can’t assume that your users live in your country and speak your language.

  • Search – Do users search for what you expect them to? Do they make spelling mistakes in their queries that appropriate suggestions could minimise?

Continue reading “The analytics checklist: what to measure and look for”

Delivering an Android app for a large established non-tech company: lessons learned

The last year or so, I’ve been the lead developer for the Android mobile team at British Airways. I was brought on board to help deliver the newly designed app, which we shipped on time on 21st May 2014.

British Airways is a company with a large IT department but, when I joined, very little Android expertise. I think quite a few other Android developers may find themselves in a similar situation, so, hopefully, sharing my lessons learned will benefit others.

Disclaimer: this blog post is my opinion only and doesn’t necessarily reflect the opinion of my employer or colleagues. Blah blah, you know the legal blurb.

Lesson 1: It’s important to evangelise about Android up and down the business ladder

Continue reading “Delivering an Android app for a large established non-tech company: lessons learned”