Device Client Information

This is a plugin that lets you get basic information from your application's client. It's easy to use and supports different platforms (Android). There are four different information types: "application information", "software information", "operating system information", and "device information".

Information Types

There are 4 different types:

  1. Application Information
  2. Software Information
  3. Operating System Information
  4. Device Information

Application Information

Application information is all about the application you build. And notice that applicationId is not supported for web applications.

Attribute Android
applicationId
String

package name
applicationType
String (app/web)
applicationName
String
applicationVersion
String
applicationBuildCode
String

Software Information

"Software" stands for the "software" that runs your application, such as "Operating System" for iOS/Android projects or "Browser" for web projects.

Attribute Android
softwareName
String

OS name
softwareVersion
String

OS version

Operating System Information

OS information will show you the OS's name and version. Notice: Web projects may not get this information if the browser's user-agent doesn't contain any information about the operating system.

Attribute Android
osName
String

OS name
osVersion
String

OS version
osVersionCode
String

Android API level

Device Information

The device information will display device's ID and name. Note that web projects don't support real deviceId, so they will use the package uuid to generate a unique string and save to the browser's cookie.

Attribute Android
deviceId
String
deviceName
String

Getting Started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  device_client_information: ^0.0.1

In your project add the following import:

import 'package:client_information/client_information.dart';

Then, you can get information like this:

// Get client information
DeviceInformation info = await DeviceInformation.fetch();

print(info.deviceId); // EA625164-4XXX-XXXX-XXXXXXXXXXXX
print(info.osName); // iOS

Decoration

Starting from version 2.1.0, you can customize some information by passing the decorators. Like below:

var information = await DeviceInformation.fetch(
      // you can pass decorators to decoration the value before it return.
      decorators: ClientInformationDecorators(
        deviceId: (oriInfo, value) =>
            'prefix-$value-${oriInfo.applicationName}',
      ),
    );

Or, you can use extension method like this:

var information = await DeviceInformation.fetch();
print('Original DeviceId: ${information.deviceId}');
// Original DeviceId: EA625164-4XXX-XXXX-XXXXXXXXXXXX

var decoratedInfo = information.decoration(deviceId: (oriInfo, value) => '$value-some-suffix-string-here');
print('Decorated DeviceId: ${decoratedInfo.deviceId}');
// Decorated DeviceId: EA625164-4XXX-XXXX-XXXXXXXXXXXX-some-suffix-string-here

Mock Data for Test

Starting from version 1.0.2, you can mock data or enable "mockMode" to facilitate testing. Here is how to set it up:


In your test file:

setUp(() async {
  // Change to "MockMode" and set the default data you need.
  DeviceInformation.mockOn(
      deviceId: 'mock_device_id', osName: 'MyCustomOS');
});

tearDown(() {
  // Close the "MockMode" in tearDown method
  DeviceInformation.mockOff();
});

// Run your test
test('`deviceId` will be "mock_device_id"', () async {
DeviceInformation info = await DeviceInformation.fetch();
  expect(info.deviceId, 'mock_device_id');
});

Libraries

device_information