native_id 1.0.0 copy "native_id: ^1.0.0" to clipboard
native_id: ^1.0.0 copied to clipboard

A Flutter package to retrieve unique device identifiers and comprehensive device information across different platforms.

A Flutter package to retrieve unique device identifiers and comprehensive device information across different platforms (Android, iOS, Windows, macOS, Linux, and Web).

Pub Version

Features #

  • ✅ Get unique device identifiers for all platforms
  • ✅ Retrieve comprehensive device information
  • ✅ Support for Android, iOS, Windows, macOS, Linux, and Web
  • ✅ Type-safe model classes
  • ✅ Easy to use API

Platform Support #

Platform Identifier Type Description
Android Android ID Unique per app installation and device
iOS identifierForVendor Persists until all apps from vendor are uninstalled
Windows Device ID System-level unique identifier
macOS System GUID System-level unique identifier
Linux Machine ID System-level unique identifier
Web Browser Fingerprint Hash based on browser info

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  native_id: ^1.0.0

Then run:

flutter pub get

Usage #

Get Device ID Only #

import 'package:native_id/native_id.dart';

// Get unique device identifier
final deviceId = await NativeIdService.getDeviceId();
print('Device ID: $deviceId');

Get Comprehensive Device Information #

import 'package:native_id/native_id.dart';

// Get detailed device information
final deviceInfo = await NativeIdService.getDeviceInfo();

print('Platform: ${deviceInfo.platform}');
print('Device ID: ${deviceInfo.deviceId}');
print('Model: ${deviceInfo.model}');
print('Manufacturer: ${deviceInfo.manufacturer}');
print('OS Version: ${deviceInfo.osVersion}');
print('Is Physical Device: ${deviceInfo.isPhysicalDevice}');

// Access additional platform-specific info
deviceInfo.additionalInfo?.forEach((key, value) {
  print('$key: $value');
});

// Convert to JSON
final json = deviceInfo.toJson();

Complete Example #

import 'package:flutter/material.dart';
import 'package:native_id/native_id.dart';

class DeviceInfoScreen extends StatefulWidget {
  @override
  _DeviceInfoScreenState createState() => _DeviceInfoScreenState();
}

class _DeviceInfoScreenState extends State<DeviceInfoScreen> {
  String? _deviceId;
  DeviceInfoModel? _deviceInfo;

  @override
  void initState() {
    super.initState();
    _loadDeviceInfo();
  }

  Future<void> _loadDeviceInfo() async {
    final deviceId = await NativeIdService.getDeviceId();
    final deviceInfo = await NativeIdService.getDeviceInfo();

    setState(() {
      _deviceId = deviceId;
      _deviceInfo = deviceInfo;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Device Info')),
      body: _deviceInfo == null
          ? Center(child: CircularProgressIndicator())
          : SingleChildScrollView(
              padding: EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('Device ID: $_deviceId'),
                  SizedBox(height: 16),
                  Text('Platform: ${_deviceInfo!.platform}'),
                  Text('Model: ${_deviceInfo!.model}'),
                  Text('Manufacturer: ${_deviceInfo!.manufacturer}'),
                  Text('OS Version: ${_deviceInfo!.osVersion}'),
                ],
              ),
            ),
    );
  }
}

Legacy #

import 'package:native_id/legacy.dart';

// Get unique device identifier
final deviceId = await NativeId.getId();
print('Device ID: $deviceId');

Important Notes #

IMEI Access Restrictions #

Android 10+: Accessing IMEI requires READ_PRIVILEGED_PHONE_STATE permission, which is only granted to system apps. Regular apps cannot access IMEI due to privacy restrictions.

iOS: IMEI is not accessible through public APIs.

This package uses the best available identifiers for each platform that don't require special permissions.

Identifier Persistence #

  • Android: androidId changes when the app is reinstalled or the device is factory reset
  • iOS: identifierForVendor persists until all apps from the same vendor are uninstalled
  • Windows/macOS/Linux: System-level identifiers are generally stable across app reinstalls

Privacy Considerations #

Always inform users if you're collecting device identifiers and comply with privacy regulations (GDPR, CCPA, etc.).

Platform-Specific Setup #

Android #

No additional setup required. The package uses device_info_plus which handles Android permissions automatically.

iOS #

No additional setup required.

Windows/macOS/Linux #

No additional setup required.

Web #

Works out of the box. The identifier is based on browser information.

API Reference #

NativeIdService #

Methods

getDeviceId()

Returns a unique device identifier as a String?.

static Future<String?> getDeviceId()
getDeviceInfo()

Returns comprehensive device information as a DeviceInfoModel.

static Future<DeviceInfoModel> getDeviceInfo()

DeviceInfoModel #

Properties

  • platform: Platform name (Android, iOS, Windows, macOS, Linux, Web)
  • deviceId: Unique device identifier
  • model: Device model
  • manufacturer: Device manufacturer
  • brand: Device brand
  • name: Device name
  • osVersion: Operating system version
  • sdkVersion: SDK/API version
  • isPhysicalDevice: Whether this is a physical device
  • additionalInfo: Additional platform-specific information
  • error: Error message if any

Methods

  • toJson(): Convert to JSON
  • fromJson(Map<String, dynamic> json): Create from JSON
  • toString(): String representation

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.

Credits #

This package is built on top of device_info_plus.

4
likes
160
points
298
downloads
screenshot

Publisher

verified publisherkyawzayartun.com

Weekly Downloads

A Flutter package to retrieve unique device identifiers and comprehensive device information across different platforms.

Repository (GitHub)
View/report issues

Topics

#device #information #utils #identifier

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

device_info_plus, flutter, plugin_platform_interface

More

Packages that depend on native_id

Packages that implement native_id