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 'mono.connect.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 'mono.connect.widget.closed':
      case 'mono.modal.closed':
        if (widget.onClosed != null) widget.onClosed!();
        if (mounted) Navigator.of(context).pop();
        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;
    }
  }
}