This is the fifteenth part of my journey to build and publish a Flutter based app for the App Store and Google Play.
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.
TL:DR – The focus here is on device information which might be helpful for your app.
Asynchronous programming: futures, async, await
Theres a codelab for asynchronous programming. Asynchronous programming in Dart with 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.
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"