AutoUssdFlutter constructor

AutoUssdFlutter(
  1. _SessionCountCallback _onSessionCount,
  2. _SessionExecutionCallback _onSessionExecuted
)

Primary constructor of the library.

USSD session execution is asynchronous on the native platform thus a callback must be specified to be notified of the result

Implementation

AutoUssdFlutter(
  this._onSessionCount,
  this._onSessionExecuted,
) {
  _CHANNEL.setMethodCallHandler((call) async {
    if (call.method == _SESSION_COUNT_CALLBACK_NAME) {
      final count = call.arguments as int;

      _onSessionCount(count);
    } else if (call.method == _SESSION_RESULT_CALLBACK_NAME) {
      final List<dynamic> args = call.arguments;
      final sessionId = args[0] as String;
      final status = args[1] as String;
      final description = args[2] as String;
      final lastContent = args[3] as String?;
      final parser = args[4] as String?;

      _onSessionExecuted(
        Result._(
          sessionId,
          status,
          description,
          lastContent,
          parser,
        ),
      );
    }
  });
}