sim_data 0.0.1+2

  • Readme
  • Changelog
  • Example
  • Installing
  • new76

Sim plugin for Flutter #

A Flutter plugin to retrieve Sim cards data - dual sim support - only Android for now.

Installation #

Add sim_data as a dependency in your pubspec.yaml.

Make sure that your AndroidManifext.xml file includes the following permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Usage #

Before you use this plugin, you must make sure that the user has authorized access to his phone, for example with the permission_handler plugin.

You may then use the plugin:

import 'package:sim_data/sim_data.dart';

void printSimCardsData() async {
  try {
    SimData simData = await SimDataPlugin.getSimData();
    simData.cards.forEach((SimCard s) {
        print('Serial number: ${s.serialNumber}');
    });
  } catch(e) {
    debugPrint("error! code: ${e.code} - message: ${e.message}");
  }
}

void main() => printSimCardsData();

0.0.1+2 #

Progagates Android Exception message to Dart side

0.0.1+1 #

Fixes Exception when no sim is present

0.0.1 #

First working version

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sim_data/sim_data.dart';

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

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

class _MyAppState extends State<MyApp> {
  bool _isLoading = true;
  SimData _simData;

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

  Future<void> init() async {
    SimData simData;
    try {
      var status = await Permission.phone.status;
      if (!status.isGranted) {
        bool isGranted = await Permission.phone.request().isGranted;
        if (!isGranted) return;
      }
      simData = await SimDataPlugin.getSimData();
      setState(() {
        _isLoading = false;
        _simData = simData;
      });
      void printSimCardsData() async {
        try {
          SimData simData = await SimDataPlugin.getSimData();
          simData.cards.forEach((SimCard s) {
            print('Serial number: ${s.serialNumber}');
          });
        } catch (e) {
          debugPrint("error! code: ${e.code} - message: ${e.message}");
        }
      }

      printSimCardsData();
    } catch (e) {
      debugPrint(e.toString());
      setState(() {
        _isLoading = false;
        _simData = null;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Sim data demo'),
        ),
        body: Column(
          children: <Widget>[
            Padding(
              padding: EdgeInsets.all(20.0),
              child: Column(
                  children: _simData != null && _simData.cards is List
                      ? _simData.cards.isEmpty
                          ? [Text('No sim card present')]
                          : _simData.cards.map((SimCard card) {
                              return ListTile(
                                leading: Icon(Icons.sim_card),
                                title: Text('Card ${card.slotIndex}'),
                                subtitle: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: <Widget>[
                                    Text('carrierName: ${card.carrierName}'),
                                    Text('countryCode: ${card.countryCode}'),
                                    Text('displayName: ${card.displayName}'),
                                    Text(
                                        'isDataRoaming: ${card.isDataRoaming}'),
                                    Text(
                                        'isNetworkRoaming: ${card.isNetworkRoaming}'),
                                    Text('mcc: ${card.mcc}'),
                                    Text('mnc: ${card.mnc}'),
                                    Text('slotIndex: ${card.slotIndex}'),
                                    Text('serialNumber: ${card.serialNumber}'),
                                    Text(
                                        'subscriptionId: ${card.subscriptionId}'),
                                  ],
                                ),
                              );
                            }).toList()
                      : [
                          Center(
                            child: _isLoading
                                ? CircularProgressIndicator()
                                : Text('Failed to load data'),
                          )
                        ]),
            )
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  sim_data: ^0.0.1+2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:sim_data/sim_data.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:sim_data/sim_data.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:sim_data/sim_data.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:sim_data/sim_data.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:sim_data/sim_data.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • sim_data that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

23 out of 23 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test