handleResponse method

void handleResponse(
  1. Map<String, dynamic>? body
)

parse event from javascript channel

Implementation

void handleResponse(Map<String, dynamic>? body) {
  String? key = body!['type'];
  if (key != null) {
    switch (key) {
      // case 'withmono.comnnect.widget.account_linked':
      case 'mono.modal.linked':
        var response = body['response'];
        if (response == null) return;
        var code = response['code'];
        if (widget.onSuccess != null) widget.onSuccess!(code);
        if (mounted) Navigator.of(context).pop(code);
        break;
      // case 'withmono.comnnect.widget.closed':
      case 'mono.modal.closed':
        String? code;
        try {
          code = body['data']['code'];
        } catch (e) {
          if (kDebugMode) {
            print(e);
          }
        }
        if (code != null) widget.onSuccess?.call(code);

        widget.onClosed?.call(code);
        if (mounted) Navigator.of(context).pop(code);
        break;
      case 'mono.modal.onLoad':
        if (mounted && widget.onLoad != null) widget.onLoad!();
        break;

      default:
        final event = MonoEvent.unknown.fromString(key.split('.').last);
        if (widget.onEvent != null) {
          widget.onEvent!(event, MonoEventData.fromJson(body.getKey('data')));
        }
        break;
    }
  }
}