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)

8
  • which device/simulator are you testing? Commented Aug 18, 2018 at 21:30
  • I am testing on the Nexus 5 and on the Iphone X Commented Aug 18, 2018 at 21:35
  • none of them works for you? Commented Aug 18, 2018 at 21:35
  • did you try this plugin ? pub.dartlang.org/packages/device_id Commented Aug 18, 2018 at 21:38
  • the example at github.com/flutter/plugins/tree/master/packages/device_info works fine, just make sure you're not calling iosInfo on Android Commented Aug 18, 2018 at 21:44

4 Answers 4

3

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}
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

This package is discontinued in flutter packages.
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.

1 Comment

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.
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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.