Friday, May 29, 2020

Flutter: How to get device details like UUID, deviceName?

We will use device_info package for finding these details. Use this link to check latest version of the package. 

Add package_info: ^0.4.0+3 in pubspec.yaml file of your project.
below 
dependencies:
  flutter:
    sdk: flutter
    package_info: ^0.4.0+3


Using next code sample you can retrieve the details.

Future<List<String>> getDeviceDetails() async {
    String deviceName;
    String deviceVersion;
    String identifier;
    final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
    try {
      if (Platform.isAndroid) {
        
        var build = await deviceInfoPlugin.androidInfo;
        deviceName = build.model;
        deviceVersion = build.version.toString();
        identifier = build.androidId; //UUID for Android
      } else if (Platform.isIOS) {
        var data = await deviceInfoPlugin.iosInfo;
        deviceName = data.name;
        deviceVersion = data.systemVersion;
        identifier = data.identifierForVendor; //UUID for iOS
      }
    } on Exception catch (e) {
      print('Failed to get platform version ${e.toString()}');
    }
    return [deviceName, deviceVersion, identifier];
  }
For Iphone it returns
[iPhone Xʀ, 12.2, 0EE6BD4D-FB32-4283-B9C2-BD235DD421CF]

New to Flutter? Good resources to begin with.

Coming from Android background

https://flutter.dev/docs/get-started/flutter-for/android-devs
https://codelabs.developers.google.com/codelabs/from-java-to-dart/#0

Coming from iOS background

https://flutter.dev/docs/get-started/flutter-for/ios-devs

Find out which widget to choose:

https://flutter.dev/docs/development/ui/widgets/material

https://flutter.dev/docs/development/ui/layout

https://flutter.dev/docs/development/ui/widgets


How to use Assets?

https://flutter.dev/docs/development/ui/assets-and-images

Create flavours?

https://flutter.dev/docs/deployment/flavors

Building widget based on api Response

https://medium.com/nonstopio/flutter-future-builder-with-list-view-builder-d7212314e8c9

Building widget events of stream

https://codingwithjoe.com/flutter-building-a-widget-with-streambuilder/

Android aar deployment in Maven - 2022

Introduction If you are working on android library project, you might be wondering how to publish it on Maven like this . Earl...