4

Is there a way to get the device id for android and ios, because when I do it for android using the device_info plugin, it says this:

MissingPluginException(No implementation found for method getAndroidDeviceInfo on channel plugins.flutter.io/device_info)

Coder
  • 618
  • 2
  • 9
  • 22

4 Answers4

4

Turns out you don't actually need a package all the functionality to get Device info is inside a flutter class called flutter.io.

You can simply tap into it with this line of code as an import :

import 'dart:io' show Platform;

then to execute platform specific code you can use :

     if (Platform.iOS)
 {//your code} 
else if (Platform.Android)
{//your other code}
Dyary
  • 753
  • 7
  • 14
1

device_id plugin works fine now with iPhone also.

Bug fixed by them and also updated to swift 4.1.x

To retrieve the id just import (import 'package:device_id/device_id.dart';) and call

String device_id = await DeviceId.getID;

You can check change-log here

Rahul Mahadik
  • 11,668
  • 6
  • 41
  • 54
1

Let me explain you this by device_info plugin.

Step 1 Add Dependency

dependencies:
  flutter:
    sdk: flutter
  device_info: ^0.4.0+1

Step 2 Import your file at beginning

  import 'package:device_info/device_info.dart';

Step 3 Create a async function to return device id.

deviceInfo() async{
  DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
  return androidInfo.id;
}

Step 4 Create a FutureBuilder() to display device id or perform any action.

FutureBuilder(
  future: deviceInfo(),
  builder: (BuildContext context, AsyncSnapshot snap){
    // do nothing...
    if (snap.hasData){
      //your logic goes here.
    }else {
      return new CircularProgressIndicator();
    }
  },
)

I hope that helps you.

Akram Chauhan
  • 1,006
  • 1
  • 12
  • 19
  • It's known to be null sometimes, it's documented as "can change upon factory reset". Use at your own risk, and it can be easily changed on a rooted phone. – Kamlesh Aug 31 '20 at 09:00
1
  1. Add version in pubspec.yaml like below and click get dependencies.
    device_id: ^0.2.0

  2. Add import Statement
    import 'package:device_id/device_id.dart';

  3. and call
    String device_id = await DeviceId.getID;

cloned
  • 6,346
  • 4
  • 26
  • 38
Deepya
  • 107
  • 1
  • 4