ussd_service | Flutter Package

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

Add ussd_service as a dependency in your pubspec.yaml.

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

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: $ – message: $”); } }; makeMyRequest();

First working version of the plugin.

Fixes AndroidManifest.xml unnecessary declaration.

Improves documentation and example project

Removes pubspec.lock

Adds CHANGELOG entry

Upgrades to Android embedding V2 after release of Flutter 1.12 stable


Demonstrates how to use the Flutter plugin ussd_service.

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

  1. Clone the plugin repository:

git clone

  1. Open the “example” folder with your IDE or editor.
  2. Install the project dependencies.
  3. Run the application.

If you prefer to test it directly in your project:

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

  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 { RequestState _requestState; String _requestCode = “”; String _responseCode = “”; String _responseMessage = “”; Future sendUssdRequest() async { setState(() { _requestState = RequestState.Ongoing; }); try { String responseMessage; await PermissionHandler().requestPermissions([]); SimData simData = await SimService.getSimData; if (simData == null) { debugPrint(“simData cant be null”); return; } responseMessage = await UssdService.makeRequest(, _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: [ TextFormField( decoration: InputDecoration( labelText: ‘Enter Code’, ), onChanged: (newValue) { setState(() { _requestCode = newValue; }); }, ), SizedBox( height: 20, ), MaterialButton( color:, 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’;

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

  • Dart: 2.7.1
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

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.



Leave a Reply

Your email address will not be published. Required fields are marked *