How to get dual sim number in flutter programmatically

To get the dual SIM number programmatically in Flutter, you can use the flutter_sim_check package. This package provides a simple way to check the number of SIM cards and retrieve their details.

Follow the steps below to retrieve the dual SIM number:

  1. Add the flutter_sim_check dependency in your pubspec.yaml file:
    dependencies:
      flutter_sim_check: ^0.1.1
    
  2. Import the flutter_sim_check package in your Dart file:
    import 'package:flutter_sim_check/flutter_sim_check.dart';
    
  3. Use the FlutterSimCheck.checkSimCards() method to retrieve the SIM cards details. This method returns a Future that resolves to a SimCards object. You can access the dual SIM number using the SimCards.cards[0].number or SimCards.cards[1].number property.

    SimCards simCards = await FlutterSimCheck.checkSimCards();
    String dualSimNumber = simCards.cards[0].number; // First SIM card number
    String secondSimNumber = simCards.cards[1].number; // Second SIM card number
    

Here’s a complete example of how to implement the above steps in a Flutter app:

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

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

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

class _MyAppState extends State<MyApp> {
  String dualSimNumber = '';

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

  Future<void> getDualSimNumber() async {
    SimCards simCards = await FlutterSimCheck.checkSimCards();
    setState(() {
      dualSimNumber = simCards.cards[0].number;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Dual SIM Number'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Dual SIM Number:'),
              Text(
                dualSimNumber,
                style: TextStyle(fontSize: 18),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

In the above example, the _MyAppState class is responsible for fetching and displaying the dual SIM number. The getDualSimNumber() method is called in the initState() to retrieve the number and update the state. The dualSimNumber is then displayed in the app’s UI.

Leave a comment