custom_notification_method_channel.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'dart:async';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/services.dart';
  4. import 'custom_notification_platform_interface.dart';
  5. /// An implementation of [CustomNotificationPlatform] that uses method channels.
  6. class MethodChannelCustomNotification extends CustomNotificationPlatform {
  7. /// The method channel used to interact with the native platform.
  8. @visibleForTesting
  9. final methodChannel = const MethodChannel('custom_notification');
  10. MethodChannelCustomNotification() {
  11. methodChannel.setMethodCallHandler(_handleMethod);
  12. }
  13. final StreamController<String> _recordActionStreamController =
  14. StreamController<String>.broadcast();
  15. Future<dynamic> _handleMethod(MethodCall call) async {
  16. debugPrint(
  17. 'MethodChannelCustomNotification _handleMethod ${call.method}');
  18. switch (call.method) {
  19. case "recordAction":
  20. _recordAction(call.arguments);
  21. break;
  22. }
  23. }
  24. void _recordAction(dynamic action) {
  25. if (action is String) {
  26. _recordActionStreamController.add(action);
  27. }
  28. }
  29. @override
  30. Stream<String> recordActionStream() {
  31. return _recordActionStreamController.stream;
  32. }
  33. @override
  34. Future<void> showRecordNotification(
  35. int notificationId, bool isRecording, String timeDesc,
  36. {required String channelId, required String channelName}) async {
  37. return await methodChannel.invokeMethod("showRecordNotification", {
  38. "notificationId": notificationId,
  39. "isRecording": isRecording,
  40. "timeDesc": timeDesc,
  41. "channelId": channelId,
  42. "channelName": channelName,
  43. });
  44. }
  45. }