How to find test device id in flutter

How to find the test device ID in Flutter

In order to find the test device ID, we will use device_id plugin for flutter.

Install device_id Plugin

  • Add the packages’s pubspec.yaml file

    1
    2
    dependencies:
    device_id: ^0.2.0
  • Get the packages

    1
    $ flutter pub get
  • Import the packages

    1
    import 'package:device_id/device_id.dart';

How to get the test device ID using device_id Plugin

  • Change your main.dart file as below and run your app.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    import 'package:flutter/material.dart';
    import 'package:device_id/device_id.dart';

    void main() => runApp(new MyApp());

    class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() => new _MyAppState();
    }

    class _MyAppState extends State<MyApp> {
    String deviceID;

    void getDeviceID() async {
    String deviceId = await DeviceId.getID;
    deviceID = 'Device ID is $deviceId';
    print('Device ID is $deviceId');
    }

    @override
    Widget build(BuildContext context) {
    getDeviceID();
    return MaterialApp(
    home: Scaffold(
    appBar: new AppBar(
    title: const Text('Device Id example app'),
    ),
    body: Center(
    child: Text('$deviceID'),
    ),
    ),
    );
    }
    }
Share