eSim Installer Flutter Plugin

The esim_installer_flutter plugin provides a Flutter interface to interact with eSIM installation and management functionality on the native platform (currently Android). This plugin allows Flutter applications to install eSIM profiles, check if the device supports eSIM, and provide instructions for eSIM setup.

Features

Get Platform Version: Retrieve the version of the underlying Android platform.
Check eSIM Support: Determine whether the device supports eSIM functionality.
Install eSIM Profile: Initiate the installation of an eSIM profile using a specified SMDP address and activation token.
Launch Intent: Directly launch an intent to handle eSIM profile installation.
Get Installation Instructions: Obtain step-by-step instructions for manually installing an eSIM profile.

Installation

To use this plugin, add `esim_installer_flutter` as a dependency in your `pubspec.yaml` file:
dependencies:
  esim_installer_flutter:
    git:
      url: https://github.com/rai-ms/esim_installer_flutter.git

Usage

Import the esim_installer_flutter plugin in your Dart code:

import 'package:esim_installer_flutter/esim_installer_flutter.dart';

Example


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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: EsimInstallerHome(),
    );
  }
}

class EsimInstallerHome extends StatefulWidget {
  @override
  _EsimInstallerHomeState createState() => _EsimInstallerHomeState();
}

class _EsimInstallerHomeState extends State<EsimInstallerHome> {
  String _platformVersion = 'Unknown';
  bool _isEsimSupported = false;
  String _installationResult = '';
  String _instructions = '';

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

  Future<void> _initPlatformState() async {
    String platformVersion;
    bool isEsimSupported;
    String instructions;

    try {
      platformVersion = await EsimInstallerFlutter().getPlatformVersion() ?? 'Unknown platform version';
      isEsimSupported = await EsimInstallerFlutter().isSupportESim() ?? false;
      instructions = await EsimInstallerFlutter().instructions() ?? 'No instructions available';
    } catch (e) {
      platformVersion = 'Failed to get platform version.';
      isEsimSupported = false;
      instructions = 'Failed to get instructions.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
      _isEsimSupported = isEsimSupported;
      _instructions = instructions;
    });
  }

  Future<void> _installEsimProfile() async {
    String result;
    try {
      result = await EsimInstallerFlutter().installESimProfile(
        smdpAddress: 'your.smdp.address',
        activationToken: 'your_activation_token',
      );
    } catch (e) {
      result = 'Failed to install eSIM profile.';
    }

    setState(() {
      _installationResult = result;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('eSIM Installer Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('Running on: $_platformVersion\n'),
            Text('eSIM Supported: $_isEsimSupported\n'),
            ElevatedButton(
              onPressed: _isEsimSupported ? _installEsimProfile : null,
              child: Text('Install eSIM Profile'),
            ),
            Text('Installation Result: $_installationResult\n'),
            ElevatedButton(
              onPressed: () {
                showDialog(
                  context: context,
                  builder: (context) => AlertDialog(
                    title: Text('eSIM Installation Instructions'),
                    content: Text(_instructions),
                    actions: <Widget>[
                      TextButton(
                        onPressed: () => Navigator.pop(context),
                        child: Text('OK'),
                      ),
                    ],
                  ),
                );
              },
              child: Text('Show Instructions'),
            ),
          ],
        ),
      ),
    );
  }
}