Flutter get imei

Flutter get IMEI

To get the International Mobile Equipment Identity (IMEI) of a device in a Flutter application, you can use the flutter_imei package. This package provides a simple API to fetch the IMEI number of the device.

Step 1: Add dependency

To use the flutter_imei package, add it as a dependency in your pubspec.yaml file:

dependencies:
  flutter_imei: ^1.0.0
    

Step 2: Import the package

In the Dart file where you want to retrieve the IMEI number, import the flutter_imei package:

import 'package:flutter_imei/flutter_imei.dart';
    

Step 3: Get the IMEI number

Use the static method ‘getImeiMEID’ provided by the flutter_imei package to fetch the IMEI number:

String imei = await FlutterImei.getImeiMEID;
    

Example

Here’s an example to retrieve the IMEI number of a device:

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

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State {
  String imei = '';

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

  Future getIMEI() async {
    String imeiNumber = await FlutterImei.getImeiMEID;
    setState(() {
      imei = imeiNumber;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Get IMEI',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Flutter Get IMEI'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'IMEI: $imei',
                style: TextStyle(fontSize: 18),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
    

Leave a comment