ussd_service 0.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

Ussd plugin for Flutter #

This plugin makes it possible to access Android's sendUssdRequest method from a Flutter application.

Installation #

Add ussd_service as a dependency in your pubspec.yaml.

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

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

Usage #

Before you use this plugin, you must:

You may then use the plugin:

import 'package:ussd_service/ussd_service.dart';

makeMyRequest() async {
  int subscriptionId = 1; // sim card subscription ID
  String code = "*21#"; // ussd code payload
  try {
    String ussdResponseMessage = await UssdService.makeRequest(subscriptionId, code);
    print("succes! message: $ussdResponseMessage");
  } catch(e) {
    debugPrint("error! code: ${e.code} - message: ${e.message}");
  }
};

makeMyRequest();

0.0.1 - 2019-10-02 #

First working version of the plugin.

0.0.2 - 2019-10-03 #

Fixes AndroidManifest.xml unnecessary declaration.

0.0.3 - 2019-11-28 #

Improves documentation and example project

0.0.3+1 - 2019-11-29 #

Removes pubspec.lock

0.0.3+2 - 2019-11-29 #

Adds CHANGELOG entry

0.0.4 - 2019-12-14 #

Upgrades to Android embedding V2 after release of Flutter 1.12 stable

example/README.md

ussd_service example #

Demonstrates how to use the Flutter plugin ussd_service.

Test the example project #

If you want to test the plugin in its own project:

  1. Clone the plugin repository:
git clone https://github.com/vkammerer/ussd_service.git
  1. Open the "example" folder with your IDE or editor.
  2. Install the project dependencies.
  3. Run the application.

Or test in your project #

If you prefer to test it directly in your project:

  1. Make sure that your AndroidManifext.xml file includes the following permission:
<uses-permission android:name="android.permission.CALL_PHONE" />
  1. Add ussd_service, permission_handler and sim_service as a dependencies in your pubspec.yaml.

  2. Then include and adapt the following code to your project.

import 'dart:async';

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

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

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

enum RequestState {
  Ongoing,
  Success,
  Error,
}

class _MyAppState extends State<MyApp> {
  RequestState _requestState;
  String _requestCode = "";
  String _responseCode = "";
  String _responseMessage = "";

  Future<void> sendUssdRequest() async {
    setState(() {
      _requestState = RequestState.Ongoing;
    });
    try {
      String responseMessage;
      await PermissionHandler().requestPermissions([PermissionGroup.phone]);
      SimData simData = await SimService.getSimData;
      if (simData == null) {
        debugPrint("simData cant be null");
        return;
      }
      responseMessage = await UssdService.makeRequest(
          simData.cards.first.subscriptionId, _requestCode);
      setState(() {
        _requestState = RequestState.Success;
        _responseMessage = responseMessage;
      });
    } catch (e) {
      setState(() {
        _requestState = RequestState.Error;
        _responseCode = e.code;
        _responseMessage = e.message;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Ussd Plugin demo'),
        ),
        body: Container(
          padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
          child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                TextFormField(
                  decoration: InputDecoration(
                    labelText: 'Enter Code',
                  ),
                  onChanged: (newValue) {
                    setState(() {
                      _requestCode = newValue;
                    });
                  },
                ),
                SizedBox(
                  height: 20,
                ),
                MaterialButton(
                  color: Colors.blue,
                  textColor: Colors.white,
                  onPressed: _requestState == RequestState.Ongoing
                      ? null
                      : () {
                          sendUssdRequest();
                        },
                  child: Text('Send Ussd request'),
                ),
                SizedBox(
                  height: 20,
                ),
                if (_requestState == RequestState.Ongoing)
                  Text('Ongoing request...'),
                if (_requestState == RequestState.Success) ...[
                  Text('Last request was successful.'),
                  SizedBox(height: 10),
                  Text('Response was:'),
                  Text(
                    _responseMessage,
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                ],
                if (_requestState == RequestState.Error) ...[
                  Text('Last request was not successful'),
                  SizedBox(height: 10),
                  Text('Error code was:'),
                  Text(
                    _responseCode,
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                  SizedBox(height: 10),
                  Text('Error message was:'),
                  Text(
                    _responseMessage,
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                ]
              ]),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  ussd_service: ^0.0.4

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:ussd_service/ussd_service.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
66
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Health suggestions

Format lib/ussd_service.dart.

Run flutter format to format lib/ussd_service.dart.

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.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
pedantic ^1.8.0