From 49192d0efbe799e329eb0876ca1a26c471b19604 Mon Sep 17 00:00:00 2001 From: icodelifee Date: Mon, 26 Sep 2022 15:13:26 +0530 Subject: [PATCH 1/3] feat: changes to call kit methods to use dart models instead of dynamic types and Maps --- lib/entities/android_params.dart | 30 +++ lib/entities/android_params.g.dart | 32 +++ lib/entities/call_event.dart | 58 +++++ lib/entities/call_kit_params.dart | 47 ++++ lib/entities/call_kit_params.g.dart | 49 +++++ lib/entities/entities.dart | 4 + lib/entities/ios_params.dart | 42 ++++ lib/entities/ios_params.g.dart | 45 ++++ lib/flutter_callkit_incoming.dart | 105 +++------ pubspec.lock | 326 ++++++++++++++++++++++++++-- pubspec.yaml | 3 + 11 files changed, 653 insertions(+), 88 deletions(-) create mode 100644 lib/entities/android_params.dart create mode 100644 lib/entities/android_params.g.dart create mode 100644 lib/entities/call_event.dart create mode 100644 lib/entities/call_kit_params.dart create mode 100644 lib/entities/call_kit_params.g.dart create mode 100644 lib/entities/entities.dart create mode 100644 lib/entities/ios_params.dart create mode 100644 lib/entities/ios_params.g.dart diff --git a/lib/entities/android_params.dart b/lib/entities/android_params.dart new file mode 100644 index 00000000..2bc7fe26 --- /dev/null +++ b/lib/entities/android_params.dart @@ -0,0 +1,30 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'android_params.g.dart'; + +@JsonSerializable(explicitToJson: true) +class AndroidParams { + const AndroidParams({ + this.isCustomNotification, + this.isShowLogo, + this.isShowCallback, + this.isShowMissedCallNotification, + this.ringtonePath, + this.backgroundColor, + this.backgroundUrl, + this.actionColor, + }); + + final bool? isCustomNotification; + final bool? isShowLogo; + final bool? isShowCallback; + final bool? isShowMissedCallNotification; + final String? ringtonePath; + final String? backgroundColor; + final String? backgroundUrl; + final String? actionColor; + + factory AndroidParams.fromJson(Map json) => _$AndroidParamsFromJson(json); + + Map toJson() => _$AndroidParamsToJson(this); +} diff --git a/lib/entities/android_params.g.dart b/lib/entities/android_params.g.dart new file mode 100644 index 00000000..2493910b --- /dev/null +++ b/lib/entities/android_params.g.dart @@ -0,0 +1,32 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'android_params.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +AndroidParams _$AndroidParamsFromJson(Map json) => + AndroidParams( + isCustomNotification: json['isCustomNotification'] as bool?, + isShowLogo: json['isShowLogo'] as bool?, + isShowCallback: json['isShowCallback'] as bool?, + isShowMissedCallNotification: + json['isShowMissedCallNotification'] as bool?, + ringtonePath: json['ringtonePath'] as String?, + backgroundColor: json['backgroundColor'] as String?, + backgroundUrl: json['backgroundUrl'] as String?, + actionColor: json['actionColor'] as String?, + ); + +Map _$AndroidParamsToJson(AndroidParams instance) => + { + 'isCustomNotification': instance.isCustomNotification, + 'isShowLogo': instance.isShowLogo, + 'isShowCallback': instance.isShowCallback, + 'isShowMissedCallNotification': instance.isShowMissedCallNotification, + 'ringtonePath': instance.ringtonePath, + 'backgroundColor': instance.backgroundColor, + 'backgroundUrl': instance.backgroundUrl, + 'actionColor': instance.actionColor, + }; diff --git a/lib/entities/call_event.dart b/lib/entities/call_event.dart new file mode 100644 index 00000000..29970fc1 --- /dev/null +++ b/lib/entities/call_event.dart @@ -0,0 +1,58 @@ +class CallEvent { + Event event; + dynamic body; + + CallEvent(this.body, this.event); + @override + String toString() => 'CallEvent( body: $body, event: $event)'; +} + +enum Event { + ACTION_DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP, + ACTION_CALL_INCOMING, + ACTION_CALL_START, + ACTION_CALL_ACCEPT, + ACTION_CALL_DECLINE, + ACTION_CALL_ENDED, + ACTION_CALL_TIMEOUT, + ACTION_CALL_CALLBACK, + ACTION_CALL_TOGGLE_HOLD, + ACTION_CALL_TOGGLE_MUTE, + ACTION_CALL_TOGGLE_DMTF, + ACTION_CALL_TOGGLE_GROUP, + ACTION_CALL_TOGGLE_AUDIO_SESSION, +} + +// using extension for backward compatibility Dart SDK 2.17.0 and lower +extension EventX on Event { + String get name { + switch (this) { + case Event.ACTION_DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP: + return 'com.hiennv.flutter_callkit_incoming.DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP'; + case Event.ACTION_CALL_INCOMING: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_INCOMING'; + case Event.ACTION_CALL_START: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_START'; + case Event.ACTION_CALL_ACCEPT: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_ACCEPT'; + case Event.ACTION_CALL_DECLINE: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_DECLINE'; + case Event.ACTION_CALL_ENDED: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_ENDED'; + case Event.ACTION_CALL_TIMEOUT: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_TIMEOUT'; + case Event.ACTION_CALL_CALLBACK: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_CALLBACK'; + case Event.ACTION_CALL_TOGGLE_HOLD: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_HOLD'; + case Event.ACTION_CALL_TOGGLE_MUTE: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_MUTE'; + case Event.ACTION_CALL_TOGGLE_DMTF: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_DMTF'; + case Event.ACTION_CALL_TOGGLE_GROUP: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_GROUP'; + case Event.ACTION_CALL_TOGGLE_AUDIO_SESSION: + return 'com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_AUDIO_SESSION'; + } + } +} diff --git a/lib/entities/call_kit_params.dart b/lib/entities/call_kit_params.dart new file mode 100644 index 00000000..a01be193 --- /dev/null +++ b/lib/entities/call_kit_params.dart @@ -0,0 +1,47 @@ +import 'package:json_annotation/json_annotation.dart'; + +import 'android_params.dart'; +import 'ios_params.dart'; + +part 'call_kit_params.g.dart'; + +@JsonSerializable(explicitToJson: true) +class CallKitParams { + const CallKitParams({ + this.id, + this.nameCaller, + this.appName, + this.avatar, + this.handle, + this.type, + this.duration, + this.textAccept, + this.textDecline, + this.textMissedCall, + this.textCallback, + this.extra, + this.headers, + this.android, + this.ios, + }); + + final String? id; + final String? nameCaller; + final String? appName; + final String? avatar; + final String? handle; + final double? type; + final double? duration; + final String? textAccept; + final String? textDecline; + final String? textMissedCall; + final String? textCallback; + final Map? extra; + final Map? headers; + final AndroidParams? android; + final IOSParams? ios; + + factory CallKitParams.fromJson(Map json) => _$CallKitParamsFromJson(json); + + Map toJson() => _$CallKitParamsToJson(this); +} diff --git a/lib/entities/call_kit_params.g.dart b/lib/entities/call_kit_params.g.dart new file mode 100644 index 00000000..2794993a --- /dev/null +++ b/lib/entities/call_kit_params.g.dart @@ -0,0 +1,49 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'call_kit_params.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CallKitParams _$CallKitParamsFromJson(Map json) => + CallKitParams( + id: json['id'] as String?, + nameCaller: json['nameCaller'] as String?, + appName: json['appName'] as String?, + avatar: json['avatar'] as String?, + handle: json['handle'] as String?, + type: (json['type'] as num?)?.toDouble(), + duration: (json['duration'] as num?)?.toDouble(), + textAccept: json['textAccept'] as String?, + textDecline: json['textDecline'] as String?, + textMissedCall: json['textMissedCall'] as String?, + textCallback: json['textCallback'] as String?, + extra: json['extra'] as Map?, + headers: json['headers'] as Map?, + android: json['android'] == null + ? null + : AndroidParams.fromJson(json['android'] as Map), + ios: json['ios'] == null + ? null + : IOSParams.fromJson(json['ios'] as Map), + ); + +Map _$CallKitParamsToJson(CallKitParams instance) => + { + 'id': instance.id, + 'nameCaller': instance.nameCaller, + 'appName': instance.appName, + 'avatar': instance.avatar, + 'handle': instance.handle, + 'type': instance.type, + 'duration': instance.duration, + 'textAccept': instance.textAccept, + 'textDecline': instance.textDecline, + 'textMissedCall': instance.textMissedCall, + 'textCallback': instance.textCallback, + 'extra': instance.extra, + 'headers': instance.headers, + 'android': instance.android?.toJson(), + 'ios': instance.ios?.toJson(), + }; diff --git a/lib/entities/entities.dart b/lib/entities/entities.dart new file mode 100644 index 00000000..61182577 --- /dev/null +++ b/lib/entities/entities.dart @@ -0,0 +1,4 @@ +export './android_params.dart'; +export './call_event.dart'; +export './call_kit_params.dart'; +export './ios_params.dart'; diff --git a/lib/entities/ios_params.dart b/lib/entities/ios_params.dart new file mode 100644 index 00000000..fd5e8a39 --- /dev/null +++ b/lib/entities/ios_params.dart @@ -0,0 +1,42 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'ios_params.g.dart'; + +@JsonSerializable(explicitToJson: true) +class IOSParams { + final String? iconName; + final String? handleType; + final bool? supportsVideo; + final int? maximumCallGroups; + final int? maximumCallsPerCallGroup; + final String? audioSessionMode; + final bool? audioSessionActive; + final double? audioSessionPreferredSampleRate; + final double? audioSessionPreferredIOBufferDuration; + final bool? supportsDTMF; + final bool? supportsHolding; + final bool? supportsGrouping; + final bool? supportsUngrouping; + final String? ringtonePath; + + IOSParams({ + this.iconName, + this.handleType, + this.supportsVideo, + this.maximumCallGroups, + this.maximumCallsPerCallGroup, + this.audioSessionMode, + this.audioSessionActive, + this.audioSessionPreferredSampleRate, + this.audioSessionPreferredIOBufferDuration, + this.supportsDTMF, + this.supportsHolding, + this.supportsGrouping, + this.supportsUngrouping, + this.ringtonePath, + }); + + factory IOSParams.fromJson(Map json) => _$IOSParamsFromJson(json); + + Map toJson() => _$IOSParamsToJson(this); +} diff --git a/lib/entities/ios_params.g.dart b/lib/entities/ios_params.g.dart new file mode 100644 index 00000000..e0fe0f93 --- /dev/null +++ b/lib/entities/ios_params.g.dart @@ -0,0 +1,45 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'ios_params.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +IOSParams _$IOSParamsFromJson(Map json) => IOSParams( + iconName: json['iconName'] as String?, + handleType: json['handleType'] as String?, + supportsVideo: json['supportsVideo'] as bool?, + maximumCallGroups: json['maximumCallGroups'] as int?, + maximumCallsPerCallGroup: json['maximumCallsPerCallGroup'] as int?, + audioSessionMode: json['audioSessionMode'] as String?, + audioSessionActive: json['audioSessionActive'] as bool?, + audioSessionPreferredSampleRate: + (json['audioSessionPreferredSampleRate'] as num?)?.toDouble(), + audioSessionPreferredIOBufferDuration: + (json['audioSessionPreferredIOBufferDuration'] as num?)?.toDouble(), + supportsDTMF: json['supportsDTMF'] as bool?, + supportsHolding: json['supportsHolding'] as bool?, + supportsGrouping: json['supportsGrouping'] as bool?, + supportsUngrouping: json['supportsUngrouping'] as bool?, + ringtonePath: json['ringtonePath'] as String?, + ); + +Map _$IOSParamsToJson(IOSParams instance) => { + 'iconName': instance.iconName, + 'handleType': instance.handleType, + 'supportsVideo': instance.supportsVideo, + 'maximumCallGroups': instance.maximumCallGroups, + 'maximumCallsPerCallGroup': instance.maximumCallsPerCallGroup, + 'audioSessionMode': instance.audioSessionMode, + 'audioSessionActive': instance.audioSessionActive, + 'audioSessionPreferredSampleRate': + instance.audioSessionPreferredSampleRate, + 'audioSessionPreferredIOBufferDuration': + instance.audioSessionPreferredIOBufferDuration, + 'supportsDTMF': instance.supportsDTMF, + 'supportsHolding': instance.supportsHolding, + 'supportsGrouping': instance.supportsGrouping, + 'supportsUngrouping': instance.supportsUngrouping, + 'ringtonePath': instance.ringtonePath, + }; diff --git a/lib/flutter_callkit_incoming.dart b/lib/flutter_callkit_incoming.dart index af7cd6b6..24690bf6 100644 --- a/lib/flutter_callkit_incoming.dart +++ b/lib/flutter_callkit_incoming.dart @@ -2,62 +2,61 @@ import 'dart:async'; import 'package:flutter/services.dart'; +import 'entities/entities.dart'; + /// Instance to use library functions. /// * showCallkitIncoming(dynamic) /// * startCall(dynamic) /// * endCall(dynamic) /// * endAllCalls() -/// + class FlutterCallkitIncoming { - static const MethodChannel _channel = - const MethodChannel('flutter_callkit_incoming'); - static const EventChannel _eventChannel = - const EventChannel('flutter_callkit_incoming_events'); + static const MethodChannel _channel = const MethodChannel('flutter_callkit_incoming'); + static const EventChannel _eventChannel = const EventChannel('flutter_callkit_incoming_events'); /// Listen to event callback from [FlutterCallkitIncoming]. /// /// FlutterCallkitIncoming.onEvent.listen((event) { - /// CallEvent.ACTION_CALL_INCOMING - Received an incoming call - /// CallEvent.ACTION_CALL_START - Started an outgoing call - /// CallEvent.ACTION_CALL_ACCEPT - Accepted an incoming call - /// CallEvent.ACTION_CALL_DECLINE - Declined an incoming call - /// CallEvent.ACTION_CALL_ENDED - Ended an incoming/outgoing call - /// CallEvent.ACTION_CALL_TIMEOUT - Missed an incoming call - /// CallEvent.ACTION_CALL_CALLBACK - only Android (click action `Call back` from missed call notification) - /// CallEvent.ACTION_CALL_TOGGLE_HOLD - only iOS - /// CallEvent.ACTION_CALL_TOGGLE_MUTE - only iOS - /// CallEvent.ACTION_CALL_TOGGLE_DMTF - only iOS - /// CallEvent.ACTION_CALL_TOGGLE_GROUP - only iOS - /// CallEvent.ACTION_CALL_TOGGLE_AUDIO_SESSION - only iOS - /// CallEvent.DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP - only iOS + /// Event.ACTION_CALL_INCOMING - Received an incoming call + /// Event.ACTION_CALL_START - Started an outgoing call + /// Event.ACTION_CALL_ACCEPT - Accepted an incoming call + /// Event.ACTION_CALL_DECLINE - Declined an incoming call + /// Event.ACTION_CALL_ENDED - Ended an incoming/outgoing call + /// Event.ACTION_CALL_TIMEOUT - Missed an incoming call + /// Event.ACTION_CALL_CALLBACK - only Android (click action `Call back` from missed call notification) + /// Event.ACTION_CALL_TOGGLE_HOLD - only iOS + /// Event.ACTION_CALL_TOGGLE_MUTE - only iOS + /// Event.ACTION_CALL_TOGGLE_DMTF - only iOS + /// Event.ACTION_CALL_TOGGLE_GROUP - only iOS + /// Event.ACTION_CALL_TOGGLE_AUDIO_SESSION - only iOS + /// Event.DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP - only iOS /// } - static Stream get onEvent => - _eventChannel.receiveBroadcastStream().map(_receiveCallEvent); + static Stream get onEvent => _eventChannel.receiveBroadcastStream().map(_receiveCallEvent); /// Show Callkit Incoming. /// On iOS, using Callkit. On Android, using a custom UI. - static Future showCallkitIncoming(dynamic params) async { - await _channel.invokeMethod("showCallkitIncoming", params); + static Future showCallkitIncoming(CallKitParams params) async { + await _channel.invokeMethod("showCallkitIncoming", params.toJson()); } /// Show Miss Call Notification. /// Only Android - static Future showMissCallNotification(dynamic params) async { - await _channel.invokeMethod("showMissCallNotification", params); + static Future showMissCallNotification(CallKitParams params) async { + await _channel.invokeMethod("showMissCallNotification", params.toJson()); } /// Start an Outgoing call. /// On iOS, using Callkit(create a history into the Phone app). /// On Android, Nothing(only callback event listener). - static Future startCall(dynamic params) async { - await _channel.invokeMethod("startCall", params); + static Future startCall(CallKitParams params) async { + await _channel.invokeMethod("startCall", params.toJson()); } /// End an Incoming/Outgoing call. /// On iOS, using Callkit(update a history into the Phone app). /// On Android, Nothing(only callback event listener). - static Future endCall(dynamic params) async { - await _channel.invokeMethod("endCall", params); + static Future endCall(String id) async { + await _channel.invokeMethod("endCall", {'id': id}); } /// End all calls. @@ -80,52 +79,14 @@ class FlutterCallkitIncoming { } static CallEvent? _receiveCallEvent(dynamic data) { - var event = ""; - dynamic body = {}; + Event? event; + Map body = {}; + if (data is Map) { - event = data['event']; + event = Event.values.firstWhere((e) => e.name == data['event']); body = Map.from(data['body']); + return CallEvent(body, event); } - return CallEvent(event, body); - } -} - -class CallEvent { - static const String ACTION_DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP = - "com.hiennv.flutter_callkit_incoming.DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP"; - - static const String ACTION_CALL_INCOMING = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_INCOMING"; - static const String ACTION_CALL_START = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_START"; - static const String ACTION_CALL_ACCEPT = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_ACCEPT"; - static const String ACTION_CALL_DECLINE = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_DECLINE"; - static const String ACTION_CALL_ENDED = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_ENDED"; - static const String ACTION_CALL_TIMEOUT = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_TIMEOUT"; - static const String ACTION_CALL_CALLBACK = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_CALLBACK"; - static const String ACTION_CALL_TOGGLE_HOLD = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_HOLD"; - static const String ACTION_CALL_TOGGLE_MUTE = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_MUTE"; - static const String ACTION_CALL_TOGGLE_DMTF = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_DMTF"; - static const String ACTION_CALL_TOGGLE_GROUP = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_GROUP"; - static const String ACTION_CALL_TOGGLE_AUDIO_SESSION = - "com.hiennv.flutter_callkit_incoming.ACTION_CALL_TOGGLE_AUDIO_SESSION"; - - String name; - dynamic body; - - CallEvent(this.name, this.body); - - @override - String toString() { - return "{ event: ${name.toString()}, body: ${body.toString()} }"; + return null; } } diff --git a/pubspec.lock b/pubspec.lock index 30ae4886..6be07a3a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,13 +1,34 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "48.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.0" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.1" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -15,27 +36,90 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + build: + dependency: transitive + description: + name: build + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.1" + build_config: + dependency: transitive + description: + name: build_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + build_daemon: + dependency: transitive + description: + name: build_daemon + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.10" + build_runner: + dependency: "direct dev" + description: + name: build_runner + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + url: "https://pub.dartlang.org" + source: hosted + version: "7.2.4" + built_collection: + dependency: transitive + description: + name: built_collection + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + url: "https://pub.dartlang.org" + source: hosted + version: "8.4.1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: + version: "1.2.1" + checked_yaml: dependency: transitive description: - name: charcode + name: checked_yaml url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "2.0.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" + code_builder: + dependency: transitive + description: + name: code_builder + url: "https://pub.dartlang.org" + source: hosted + version: "4.3.0" collection: dependency: transitive description: @@ -43,13 +127,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.16.0" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.4" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.4" + fixnum: + dependency: transitive + description: + name: fixnum + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" flutter: dependency: "direct main" description: flutter @@ -60,46 +179,179 @@ packages: description: flutter source: sdk version: "0.0.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + graphs: + dependency: transitive + description: + name: graphs + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.1" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" + json_annotation: + dependency: "direct main" + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "4.7.0" + json_serializable: + dependency: "direct dev" + description: + name: json_serializable + url: "https://pub.dartlang.org" + source: hosted + version: "6.4.0" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.0" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.5" + source_helper: + dependency: transitive + description: + name: source_helper + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.3" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -114,27 +366,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" + timing: + dependency: transitive + description: + name: timing + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" vector_math: dependency: transitive description: @@ -142,6 +415,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.17.0 <3.0.0" flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index da05de40..9c520238 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,10 +15,13 @@ environment: dependencies: flutter: sdk: flutter + json_annotation: ^4.7.0 dev_dependencies: + build_runner: ^2.2.1 flutter_test: sdk: flutter + json_serializable: ^6.4.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec From 86dd53cf94e6aaaa92d0f0315de2374fd37c0d98 Mon Sep 17 00:00:00 2001 From: icodelifee Date: Mon, 26 Sep 2022 15:14:18 +0530 Subject: [PATCH 2/3] feat: update example app to use new dart models --- example/android/app/build.gradle | 2 +- example/lib/calling_page.dart | 70 ++++++------ example/lib/home_page.dart | 186 +++++++++++++++---------------- example/lib/main.dart | 120 ++++++++++---------- example/pubspec.lock | 41 ++++--- 5 files changed, 208 insertions(+), 211 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index f9acad76..957a8c18 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -27,7 +27,7 @@ apply plugin: 'com.google.gms.google-services' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 31 + compileSdkVersion 33 sourceSets { main.java.srcDirs += 'src/main/kotlin' diff --git a/example/lib/calling_page.dart b/example/lib/calling_page.dart index 16a05b8a..0a4b4009 100644 --- a/example/lib/calling_page.dart +++ b/example/lib/calling_page.dart @@ -1,4 +1,7 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; +import 'package:flutter_callkit_incoming/entities/entities.dart'; import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; import 'package:flutter_callkit_incoming_example/navigation_service.dart'; import 'package:http/http.dart'; @@ -11,52 +14,53 @@ class CallingPage extends StatefulWidget { } class CallingPageState extends State { - late dynamic calling; + late CallKitParams? calling; @override Widget build(BuildContext context) { - calling = ModalRoute.of(context)!.settings.arguments; - print(calling); + final params = jsonDecode(jsonEncode(ModalRoute.of(context)!.settings.arguments as Map)); + calling = CallKitParams.fromJson(params); + debugPrint(calling?.toJson().toString()); return Scaffold( - body: Container( - height: MediaQuery.of(context).size.height, - width: double.infinity, - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text('Calling...'), - TextButton( - style: ButtonStyle( - foregroundColor: - MaterialStateProperty.all(Colors.blue), - ), - onPressed: () async { - FlutterCallkitIncoming.endCall(calling); - calling = null; - NavigationService.instance.goBack(); - await requestHttp('END_CALL'); - }, - child: Text('End Call'), - ) - ], - ), - ))); + body: Container( + height: MediaQuery.of(context).size.height, + width: double.infinity, + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text('Calling...'), + TextButton( + style: ButtonStyle( + foregroundColor: MaterialStateProperty.all(Colors.blue), + ), + onPressed: () async { + if (calling != null) { + FlutterCallkitIncoming.endCall(calling!.id!); + calling = null; + } + NavigationService.instance.goBack(); + await requestHttp('END_CALL'); + }, + child: Text('End Call'), + ) + ], + ), + ), + ), + ); } //check with https://webhook.site/#!/2748bc41-8599-4093-b8ad-93fd328f1cd2 Future requestHttp(content) async { - get(Uri.parse( - 'https://webhook.site/2748bc41-8599-4093-b8ad-93fd328f1cd2?data=$content')); + get(Uri.parse('https://webhook.site/2748bc41-8599-4093-b8ad-93fd328f1cd2?data=$content')); } @override void dispose() { super.dispose(); - if (calling != null) { - FlutterCallkitIncoming.endCall(calling); - } + if (calling != null) FlutterCallkitIncoming.endCall(calling!.id!); } } diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index e32acec4..7d43174c 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -1,11 +1,15 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; +import 'package:flutter_callkit_incoming/entities/android_params.dart'; +import 'package:flutter_callkit_incoming/entities/call_event.dart'; +import 'package:flutter_callkit_incoming/entities/call_kit_params.dart'; +import 'package:flutter_callkit_incoming/entities/ios_params.dart'; import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; import 'package:flutter_callkit_incoming_example/app_router.dart'; import 'package:flutter_callkit_incoming_example/navigation_service.dart'; -import 'package:uuid/uuid.dart'; -import 'dart:async'; -import 'dart:convert'; import 'package:http/http.dart'; +import 'package:uuid/uuid.dart'; class HomePage extends StatefulWidget { @override @@ -15,9 +19,9 @@ class HomePage extends StatefulWidget { } class HomePageState extends State { - var _uuid; - var _currentUuid; - var textEvents = ""; + late final Uuid _uuid; + String? _currentUuid; + String textEvents = ""; @override void initState() { @@ -40,45 +44,35 @@ class HomePageState extends State { Icons.call, color: Colors.white, ), - onPressed: () async { - this.makeFakeCallInComing(); - }, + onPressed: makeFakeCallInComing, ), IconButton( icon: Icon( Icons.call_end, color: Colors.white, ), - onPressed: () async { - this.endCurrentCall(); - }, + onPressed: endCurrentCall, ), IconButton( icon: Icon( Icons.call_made, color: Colors.white, ), - onPressed: () async { - this.startOutGoingCall(); - }, + onPressed: startOutGoingCall, ), IconButton( icon: Icon( Icons.call_merge, color: Colors.white, ), - onPressed: () async { - this.activeCalls(); - }, + onPressed: activeCalls, ), IconButton( icon: Icon( Icons.clear_all_sharp, color: Colors.white, ), - onPressed: () async { - this.endAllCalls(); - }, + onPressed: endAllCalls, ) ], ), @@ -109,10 +103,10 @@ class HomePageState extends State { if (calls is List) { if (calls.isNotEmpty) { print('DATA: $calls'); - this._currentUuid = calls[0]['id']; + _currentUuid = calls[0]['id']; return calls[0]; } else { - this._currentUuid = ""; + _currentUuid = ""; return null; } } @@ -120,71 +114,68 @@ class HomePageState extends State { Future makeFakeCallInComing() async { await Future.delayed(const Duration(seconds: 10), () async { - this._currentUuid = _uuid.v4(); - var params = { - 'id': _currentUuid, - 'nameCaller': 'Hien Nguyen', - 'appName': 'Callkit', - 'avatar': 'https://i.pravatar.cc/100', - 'handle': '0123456789', - 'type': 0, - 'duration': 30000, - 'textAccept': 'Accept', - 'textDecline': 'Decline', - 'textMissedCall': 'Missed call', - 'textCallback': 'Call back', - 'extra': {'userId': '1a2b3c4d'}, - 'headers': { - 'apiKey': 'Abc@123!', - 'platform': 'flutter' - }, - 'android': { - 'isCustomNotification': true, - 'isShowLogo': false, - 'isShowCallback': true, - 'isShowMissedCallNotification': true, - 'ringtonePath': 'system_ringtone_default', - 'backgroundColor': '#0955fa', - 'backgroundUrl': 'assets/test.png', - 'actionColor': '#4CAF50' - }, - 'ios': { - 'iconName': 'CallKitLogo', - 'handleType': '', - 'supportsVideo': true, - 'maximumCallGroups': 2, - 'maximumCallsPerCallGroup': 1, - 'audioSessionMode': 'default', - 'audioSessionActive': true, - 'audioSessionPreferredSampleRate': 44100.0, - 'audioSessionPreferredIOBufferDuration': 0.005, - 'supportsDTMF': true, - 'supportsHolding': true, - 'supportsGrouping': false, - 'supportsUngrouping': false, - 'ringtonePath': 'system_ringtone_default' - } - }; + _currentUuid = _uuid.v4(); + + final params = CallKitParams( + id: _currentUuid, + nameCaller: 'Hien Nguyen', + appName: 'Callkit', + avatar: 'https://i.pravatar.cc/100', + handle: '0123456789', + type: 0, + duration: 30000, + textAccept: 'Accept', + textDecline: 'Decline', + textMissedCall: 'Missed call', + textCallback: 'Call back', + extra: {'userId': '1a2b3c4d'}, + headers: {'apiKey': 'Abc@123!', 'platform': 'flutter'}, + android: AndroidParams( + isCustomNotification: true, + isShowLogo: false, + isShowCallback: true, + isShowMissedCallNotification: true, + ringtonePath: 'system_ringtone_default', + backgroundColor: '#0955fa', + backgroundUrl: 'assets/test.png', + actionColor: '#4CAF50', + ), + ios: IOSParams( + iconName: 'CallKitLogo', + handleType: '', + supportsVideo: true, + maximumCallGroups: 2, + maximumCallsPerCallGroup: 1, + audioSessionMode: 'default', + audioSessionActive: true, + audioSessionPreferredSampleRate: 44100.0, + audioSessionPreferredIOBufferDuration: 0.005, + supportsDTMF: true, + supportsHolding: true, + supportsGrouping: false, + supportsUngrouping: false, + ringtonePath: 'system_ringtone_default', + ), + ); await FlutterCallkitIncoming.showCallkitIncoming(params); }); } Future endCurrentCall() async { initCurrentCall(); - var params = {'id': this._currentUuid}; - await FlutterCallkitIncoming.endCall(params); + await FlutterCallkitIncoming.endCall(_currentUuid!); } Future startOutGoingCall() async { - this._currentUuid = _uuid.v4(); - var params = { - 'id': this._currentUuid, - 'nameCaller': 'Hien Nguyen', - 'handle': '0123456789', - 'type': 1, - 'extra': {'userId': '1a2b3c4d'}, - 'ios': {'handleType': 'number'} - }; //number/email + _currentUuid = _uuid.v4(); + final params = CallKitParams( + id: _currentUuid, + nameCaller: 'Hien Nguyen', + handle: '0123456789', + type: 1, + extra: {'userId': '1a2b3c4d'}, + ios: IOSParams(handleType: 'number'), + ); await FlutterCallkitIncoming.startCall(params); } @@ -198,8 +189,7 @@ class HomePageState extends State { } Future getDevicePushTokenVoIP() async { - var devicePushTokenVoIP = - await FlutterCallkitIncoming.getDevicePushTokenVoIP(); + var devicePushTokenVoIP = await FlutterCallkitIncoming.getDevicePushTokenVoIP(); print(devicePushTokenVoIP); } @@ -207,49 +197,48 @@ class HomePageState extends State { try { FlutterCallkitIncoming.onEvent.listen((event) async { print('HOME: $event'); - switch (event!.name) { - case CallEvent.ACTION_CALL_INCOMING: + switch (event!.event) { + case Event.ACTION_CALL_INCOMING: // TODO: received an incoming call break; - case CallEvent.ACTION_CALL_START: + case Event.ACTION_CALL_START: // TODO: started an outgoing call // TODO: show screen calling in Flutter break; - case CallEvent.ACTION_CALL_ACCEPT: + case Event.ACTION_CALL_ACCEPT: // TODO: accepted an incoming call // TODO: show screen calling in Flutter - NavigationService.instance - .pushNamedIfNotCurrent(AppRoute.callingPage, args: event.body); + NavigationService.instance.pushNamedIfNotCurrent(AppRoute.callingPage, args: event.body); break; - case CallEvent.ACTION_CALL_DECLINE: + case Event.ACTION_CALL_DECLINE: // TODO: declined an incoming call await requestHttp("ACTION_CALL_DECLINE_FROM_DART"); break; - case CallEvent.ACTION_CALL_ENDED: + case Event.ACTION_CALL_ENDED: // TODO: ended an incoming/outgoing call break; - case CallEvent.ACTION_CALL_TIMEOUT: + case Event.ACTION_CALL_TIMEOUT: // TODO: missed an incoming call break; - case CallEvent.ACTION_CALL_CALLBACK: + case Event.ACTION_CALL_CALLBACK: // TODO: only Android - click action `Call back` from missed call notification break; - case CallEvent.ACTION_CALL_TOGGLE_HOLD: + case Event.ACTION_CALL_TOGGLE_HOLD: // TODO: only iOS break; - case CallEvent.ACTION_CALL_TOGGLE_MUTE: + case Event.ACTION_CALL_TOGGLE_MUTE: // TODO: only iOS break; - case CallEvent.ACTION_CALL_TOGGLE_DMTF: + case Event.ACTION_CALL_TOGGLE_DMTF: // TODO: only iOS break; - case CallEvent.ACTION_CALL_TOGGLE_GROUP: + case Event.ACTION_CALL_TOGGLE_GROUP: // TODO: only iOS break; - case CallEvent.ACTION_CALL_TOGGLE_AUDIO_SESSION: + case Event.ACTION_CALL_TOGGLE_AUDIO_SESSION: // TODO: only iOS break; - case CallEvent.ACTION_DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP: + case Event.ACTION_DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP: // TODO: only iOS break; } @@ -262,8 +251,7 @@ class HomePageState extends State { //check with https://webhook.site/#!/2748bc41-8599-4093-b8ad-93fd328f1cd2 Future requestHttp(content) async { - get(Uri.parse( - 'https://webhook.site/2748bc41-8599-4093-b8ad-93fd328f1cd2?data=$content')); + get(Uri.parse('https://webhook.site/2748bc41-8599-4093-b8ad-93fd328f1cd2?data=$content')); } onEvent(event) { diff --git a/example/lib/main.dart b/example/lib/main.dart index 40aad83d..f6baff3f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,12 +1,15 @@ +import 'dart:async'; + import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_callkit_incoming/entities/android_params.dart'; +import 'package:flutter_callkit_incoming/entities/call_kit_params.dart'; +import 'package:flutter_callkit_incoming/entities/ios_params.dart'; +import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; import 'package:flutter_callkit_incoming_example/app_router.dart'; import 'package:flutter_callkit_incoming_example/navigation_service.dart'; -import 'dart:async'; -import 'dart:convert'; import 'package:uuid/uuid.dart'; -import 'package:firebase_messaging/firebase_messaging.dart'; -import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { print("Handling a background message: ${message.messageId}"); @@ -14,48 +17,47 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { } Future showCallkitIncoming(String uuid) async { - var params = { - 'id': uuid, - 'nameCaller': 'Hien Nguyen', - 'appName': 'Callkit', - 'avatar': 'https://i.pravatar.cc/100', - 'handle': '0123456789', - 'type': 0, - 'duration': 30000, - 'textAccept': 'Accept', - 'textDecline': 'Decline', - 'textMissedCall': 'Missed call', - 'textCallback': 'Call back', - 'extra': {'userId': '1a2b3c4d'}, - 'headers': {'apiKey': 'Abc@123!', 'platform': 'flutter'}, - 'android': { - 'isCustomNotification': true, - 'isShowLogo': false, - 'isShowCallback': false, - 'ringtonePath': 'system_ringtone_default', - 'backgroundColor': '#0955fa', - 'backgroundUrl': 'https://i.pravatar.cc/500', - 'actionColor': '#4CAF50', - 'incomingCallNotificationChannelName': "Incoming Call", - 'missedCallNotificationChannelName': "Missed Call", - }, - 'ios': { - 'iconName': 'CallKitLogo', - 'handleType': '', - 'supportsVideo': true, - 'maximumCallGroups': 2, - 'maximumCallsPerCallGroup': 1, - 'audioSessionMode': 'default', - 'audioSessionActive': true, - 'audioSessionPreferredSampleRate': 44100.0, - 'audioSessionPreferredIOBufferDuration': 0.005, - 'supportsDTMF': true, - 'supportsHolding': true, - 'supportsGrouping': false, - 'supportsUngrouping': false, - 'ringtonePath': 'system_ringtone_default' - } - }; + final params = CallKitParams( + id: uuid, + nameCaller: 'Hien Nguyen', + appName: 'Callkit', + avatar: 'https://i.pravatar.cc/100', + handle: '0123456789', + type: 0, + duration: 30000, + textAccept: 'Accept', + textDecline: 'Decline', + textMissedCall: 'Missed call', + textCallback: 'Call back', + extra: {'userId': '1a2b3c4d'}, + headers: {'apiKey': 'Abc@123!', 'platform': 'flutter'}, + android: AndroidParams( + isCustomNotification: true, + isShowLogo: false, + isShowCallback: true, + isShowMissedCallNotification: true, + ringtonePath: 'system_ringtone_default', + backgroundColor: '#0955fa', + backgroundUrl: 'assets/test.png', + actionColor: '#4CAF50', + ), + ios: IOSParams( + iconName: 'CallKitLogo', + handleType: '', + supportsVideo: true, + maximumCallGroups: 2, + maximumCallsPerCallGroup: 1, + audioSessionMode: 'default', + audioSessionActive: true, + audioSessionPreferredSampleRate: 44100.0, + audioSessionPreferredIOBufferDuration: 0.005, + supportsDTMF: true, + supportsHolding: true, + supportsGrouping: false, + supportsUngrouping: false, + ringtonePath: 'system_ringtone_default', + ), + ); await FlutterCallkitIncoming.showCallkitIncoming(params); } @@ -70,8 +72,8 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State with WidgetsBindingObserver { - var _uuid; - var _currentUuid; + late final Uuid _uuid; + String? _currentUuid; late final FirebaseMessaging _firebaseMessaging; @@ -80,7 +82,7 @@ class _MyAppState extends State with WidgetsBindingObserver { super.initState(); _uuid = Uuid(); initFirebase(); - WidgetsBinding.instance?.addObserver(this); + WidgetsBinding.instance.addObserver(this); //Check call when open app from terminated checkAndNavigationCallingPage(); } @@ -91,10 +93,10 @@ class _MyAppState extends State with WidgetsBindingObserver { if (calls is List) { if (calls.isNotEmpty) { print('DATA: $calls'); - this._currentUuid = calls[0]['id']; + _currentUuid = calls[0]['id']; return calls[0]; } else { - this._currentUuid = ""; + _currentUuid = ""; return null; } } @@ -103,8 +105,7 @@ class _MyAppState extends State with WidgetsBindingObserver { checkAndNavigationCallingPage() async { var currentCall = await getCurrentCall(); if (currentCall != null) { - NavigationService.instance - .pushNamedIfNotCurrent(AppRoute.callingPage, args: currentCall); + NavigationService.instance.pushNamedIfNotCurrent(AppRoute.callingPage, args: currentCall); } } @@ -119,7 +120,7 @@ class _MyAppState extends State with WidgetsBindingObserver { @override void dispose() { - WidgetsBinding.instance?.removeObserver(this); + WidgetsBinding.instance.removeObserver(this); super.dispose(); } @@ -130,8 +131,8 @@ class _MyAppState extends State with WidgetsBindingObserver { FirebaseMessaging.onMessage.listen((RemoteMessage message) async { print( 'Message title: ${message.notification?.title}, body: ${message.notification?.body}, data: ${message.data}'); - this._currentUuid = _uuid.v4(); - showCallkitIncoming(this._currentUuid); + _currentUuid = _uuid.v4(); + showCallkitIncoming(_currentUuid!); }); _firebaseMessaging.getToken().then((token) { print('Device Token FCM: $token'); @@ -145,15 +146,12 @@ class _MyAppState extends State with WidgetsBindingObserver { onGenerateRoute: AppRoute.generateRoute, initialRoute: AppRoute.homePage, navigatorKey: NavigationService.instance.navigationKey, - navigatorObservers: [ - NavigationService.instance.routeObserver - ], + navigatorObservers: [NavigationService.instance.routeObserver], ); } Future getDevicePushTokenVoIP() async { - var devicePushTokenVoIP = - await FlutterCallkitIncoming.getDevicePushTokenVoIP(); + var devicePushTokenVoIP = await FlutterCallkitIncoming.getDevicePushTokenVoIP(); print(devicePushTokenVoIP); } } diff --git a/example/pubspec.lock b/example/pubspec.lock index 29f374c3..e2640173 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -21,7 +21,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" charcode: dependency: transitive description: @@ -35,14 +35,14 @@ packages: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" crypto: dependency: transitive description: @@ -63,7 +63,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" firebase_core: dependency: "direct main" description: @@ -117,7 +117,7 @@ packages: path: ".." relative: true source: path - version: "1.0.2+1" + version: "1.0.2+2" flutter_test: dependency: "direct dev" description: flutter @@ -148,35 +148,42 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" + json_annotation: + dependency: transitive + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "4.7.0" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.2" plugin_platform_interface: dependency: transitive description: @@ -195,7 +202,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -216,21 +223,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.12" typed_data: dependency: transitive description: @@ -251,7 +258,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" sdks: - dart: ">=2.16.0 <3.0.0" + dart: ">=2.17.0 <3.0.0" flutter: ">=1.20.0" From 62c4abac2edc59f6a6299e42a8cdf22fc6ffa187 Mon Sep 17 00:00:00 2001 From: icodelifee Date: Mon, 26 Sep 2022 15:24:18 +0530 Subject: [PATCH 3/3] fix: add back incomingCall and missedCall notification channel name params in AndroidParams --- example/lib/home_page.dart | 2 ++ lib/entities/android_params.dart | 4 ++++ lib/entities/android_params.g.dart | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index 7d43174c..73c6297c 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -139,6 +139,8 @@ class HomePageState extends State { backgroundColor: '#0955fa', backgroundUrl: 'assets/test.png', actionColor: '#4CAF50', + incomingCallNotificationChannelName: 'Incoming Call', + missedCallNotificationChannelName: 'Missed Call', ), ios: IOSParams( iconName: 'CallKitLogo', diff --git a/lib/entities/android_params.dart b/lib/entities/android_params.dart index 2bc7fe26..f2536fe4 100644 --- a/lib/entities/android_params.dart +++ b/lib/entities/android_params.dart @@ -13,6 +13,8 @@ class AndroidParams { this.backgroundColor, this.backgroundUrl, this.actionColor, + this.incomingCallNotificationChannelName, + this.missedCallNotificationChannelName, }); final bool? isCustomNotification; @@ -23,6 +25,8 @@ class AndroidParams { final String? backgroundColor; final String? backgroundUrl; final String? actionColor; + final String? incomingCallNotificationChannelName; + final String? missedCallNotificationChannelName; factory AndroidParams.fromJson(Map json) => _$AndroidParamsFromJson(json); diff --git a/lib/entities/android_params.g.dart b/lib/entities/android_params.g.dart index 2493910b..da55fb11 100644 --- a/lib/entities/android_params.g.dart +++ b/lib/entities/android_params.g.dart @@ -17,6 +17,10 @@ AndroidParams _$AndroidParamsFromJson(Map json) => backgroundColor: json['backgroundColor'] as String?, backgroundUrl: json['backgroundUrl'] as String?, actionColor: json['actionColor'] as String?, + incomingCallNotificationChannelName: + json['incomingCallNotificationChannelName'] as String?, + missedCallNotificationChannelName: + json['missedCallNotificationChannelName'] as String?, ); Map _$AndroidParamsToJson(AndroidParams instance) => @@ -29,4 +33,8 @@ Map _$AndroidParamsToJson(AndroidParams instance) => 'backgroundColor': instance.backgroundColor, 'backgroundUrl': instance.backgroundUrl, 'actionColor': instance.actionColor, + 'incomingCallNotificationChannelName': + instance.incomingCallNotificationChannelName, + 'missedCallNotificationChannelName': + instance.missedCallNotificationChannelName, };