import 'dart:async'; import 'package:flutter/services.dart'; class ReceivedIntent { final String? fromPackageName; final List? fromSignatures; final String action; final String? data; final List? categories; final Map? extra; const ReceivedIntent({ this.fromPackageName, this.fromSignatures, required this.action, this.data, this.categories, this.extra, }); factory ReceivedIntent.fromMap(Map? map) => ReceivedIntent( fromPackageName: map?["fromPackageName"], fromSignatures: map?["fromSignatures"], action: map?["action"], data: map?["data"], categories: map?["categories"], extra: (map?["extra"] as Map?)?.map( (key, value) => MapEntry(key.toString(), value)), ); } class ReceiveIntent { static const MethodChannel _methodChannel = const MethodChannel('receive_intent'); static const EventChannel _eventChannel = const EventChannel("receive_intent/event"); static Future getInitialIntent() async { final renameMap = await _methodChannel.invokeMapMethod('getInitialIntent'); print("result: $renameMap"); return ReceivedIntent.fromMap(renameMap); } static Stream receivedIntentStream = _eventChannel .receiveBroadcastStream() .map((event) => ReceivedIntent.fromMap(event as Map?)); static Future giveResult(int resultCode, {Map? data}) async { await _methodChannel.invokeMethod('giveResult', {"resultCode": resultCode, "data": data}); } }