Amazon.co.uk Widgets

This is the sixteenth part of a journey to build and publish a Flutter™ based app. Now we have started to look at sign in it gets more complicated and we need to get current device information from within our Flutter application and present choices in the user interface that are relevant.

Asynchronous programming: futures, async, await

Theres a codelab for asynchronous programming. Dart: Asynchronous programming: futures, async, await This is required for the device_info plugin which we will need in order to get the current device information from within our Flutter application.

device_info

This plugin is also a Flutter favourite, so we can use it with confidence.

 Flutter device_info pub.dev listing

The reason we need to know about futures, async and await is evident from the usage example for device_info. It uses await in order to allow time for Dart to get the answer to the questions it asks.


import 'package:device_info/device_info.dart';

DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
print('Running on ${androidInfo.model}');  // e.g. "Moto G (4)"

IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
print('Running on ${iosInfo.utsname.machine}');  // e.g. "iPod7,1"

Learning from the Codelab and putting it into practice in making device_info function