From 69c6608d0751e497eead6ab1be67bb479b58991f Mon Sep 17 00:00:00 2001 From: Enguerrand_ARMINJON_MAC_2 Date: Mon, 20 Jan 2025 15:19:39 +0100 Subject: [PATCH] feat-return-futurs --- .gitignore | 2 + analysis_options.yaml | 6 +- example/pubspec.lock | 135 +++----- example/pubspec.yaml | 6 +- lib/infobip_mobilemessaging.dart | 325 ++++++++++-------- lib/models/chat/chat_view.dart | 52 +-- lib/models/data/installation.dart | 1 + lib/models/data/personalize_context.dart | 2 +- lib/models/data/user_data.dart | 11 +- lib/models/inbox/filter_options.dart | 7 + .../default_message_storage.dart | 7 +- pubspec.lock | 205 ----------- pubspec.yaml | 4 +- test/infobip_mobilemessaging_test.dart | 29 +- test/json_test.dart | 18 +- test/utils/models_examples.dart | 57 +-- 16 files changed, 338 insertions(+), 529 deletions(-) delete mode 100644 pubspec.lock diff --git a/.gitignore b/.gitignore index 52be5ff..056f1cb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ build/ .metadata .idea *.iml + +#pubspec.lock diff --git a/analysis_options.yaml b/analysis_options.yaml index f2274e1..9df9ceb 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -22,13 +22,13 @@ linter: # `// ignore_for_file: name_of_lint` syntax on the line or in the file # producing the lint. rules: - constant_identifier_names: - ignore_for_file: installation.dart + constant_identifier_names: true directives_ordering: true prefer_relative_imports: true prefer_expression_function_bodies: true avoid_print: true # Uncomment to disable the `avoid_print` rule + require_trailing_commas: true # - prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule # Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options \ No newline at end of file +# https://dart.dev/guides/language/analysis-options diff --git a/example/pubspec.lock b/example/pubspec.lock index 59c579a..6e1dab7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,56 +5,49 @@ packages: dependency: transitive description: name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "2.11.0" + version: "2.9.0" boolean_selector: dependency: transitive description: name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.0" characters: dependency: transitive description: name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.2.1" clock: dependency: transitive description: name: clock - sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted version: "1.1.1" collection: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "1.18.0" + version: "1.16.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.8" + version: "1.0.5" fake_async: dependency: transitive description: name: fake_async - sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted version: "1.3.1" flutter: @@ -66,10 +59,9 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "3.0.2" + version: "2.0.2" flutter_test: dependency: "direct dev" description: flutter @@ -81,79 +73,49 @@ packages: path: ".." relative: true source: path - version: "7.2.0" + version: "7.2.1" intl: dependency: "direct main" description: name: intl - sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf - url: "https://pub.dev" - source: hosted - version: "0.19.0" - leak_tracker: - dependency: transitive - description: - name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" - url: "https://pub.dev" - source: hosted - version: "10.0.0" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - leak_tracker_testing: - dependency: transitive - description: - name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "0.18.1" lints: dependency: transitive description: name: lints - sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "2.0.1" matcher: dependency: transitive description: name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.16+1" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "0.8.0" + version: "0.1.5" meta: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "1.11.0" + version: "1.8.0" path: dependency: transitive description: name: path - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -163,66 +125,51 @@ packages: dependency: transitive description: name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "1.10.0" + version: "1.9.0" stack_trace: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "1.11.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted version: "1.2.1" test_api: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "0.6.1" + version: "0.4.12" vector_math: dependency: transitive description: name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 - url: "https://pub.dev" - source: hosted - version: "13.0.0" + version: "2.1.2" sdks: - dart: ">=3.2.0-0 <4.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=3.3.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 2287a26..511fd67 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -22,14 +22,14 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.6 + cupertino_icons: ^1.0.5 - intl: ^0.19.0 + intl: ^0.18.0 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^3.0.2 + flutter_lints: ^2.0.2 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/lib/infobip_mobilemessaging.dart b/lib/infobip_mobilemessaging.dart index 678b9f4..97e3c67 100644 --- a/lib/infobip_mobilemessaging.dart +++ b/lib/infobip_mobilemessaging.dart @@ -5,8 +5,6 @@ import 'dart:developer'; import 'dart:io'; import 'package:flutter/services.dart'; -import 'package:infobip_mobilemessaging/models/inbox/filter_options.dart'; -import 'package:infobip_mobilemessaging/models/inbox/inbox.dart'; import 'models/chat/ios_chat_settings.dart'; import 'models/configurations/configuration.dart'; @@ -14,14 +12,18 @@ import 'models/data/installation.dart'; import 'models/data/message.dart'; import 'models/data/personalize_context.dart'; import 'models/data/user_data.dart'; +import 'models/inbox/filter_options.dart'; +import 'models/inbox/inbox.dart'; import 'models/library_event.dart'; import 'models/message_storage/default_message_storage.dart'; import 'models/message_storage/message_storage.dart'; -enum ChatMultithreadStrategies { - all, allPlusNew, active; +enum ChatMultithreadStrategies { + all, + allPlusNew, + active; - String get stringValue { + String get stringValue { switch (this) { case ChatMultithreadStrategies.all: return 'ALL'; @@ -39,29 +41,34 @@ class InfobipMobilemessaging { static const EventChannel _libraryEvent = EventChannel('infobip_mobilemessaging/broadcast'); static final StreamSubscription _libraryEventSubscription = - _libraryEvent.receiveBroadcastStream().listen((dynamic event) { - log('Received event: $event'); - LibraryEvent libraryEvent = LibraryEvent.fromJson(jsonDecode(event)); - if (callbacks.containsKey(libraryEvent.eventName)) { - callbacks[libraryEvent.eventName]?.forEach((callback) { - log('Calling ${libraryEvent.eventName} with payload ${libraryEvent.payload == null ? 'NULL' : libraryEvent.payload.toString()}'); - if (libraryEvent.eventName == LibraryEvent.messageReceived || - libraryEvent.eventName == LibraryEvent.notificationTapped) { - callback(Message.fromJson(libraryEvent.payload)); - } else if (libraryEvent.eventName == LibraryEvent.installationUpdated) { - callback(Installation.fromJson(libraryEvent.payload).toString()); - } else if (libraryEvent.eventName == LibraryEvent.userUpdated) { - callback(UserData.fromJson(libraryEvent.payload)); - } else if (libraryEvent.payload != null) { - callback(libraryEvent.payload); - } else { - callback(libraryEvent.eventName); - } - }); - } - }, onError: (dynamic error) { - log('Received error: ${error.message}'); - }, cancelOnError: true); + _libraryEvent.receiveBroadcastStream().listen( + (dynamic event) { + log('Received event: $event'); + LibraryEvent libraryEvent = LibraryEvent.fromJson(jsonDecode(event)); + if (callbacks.containsKey(libraryEvent.eventName)) { + callbacks[libraryEvent.eventName]?.forEach((callback) { + log('Calling ${libraryEvent.eventName} with payload ${libraryEvent.payload == null ? 'NULL' : libraryEvent.payload.toString()}'); + if (libraryEvent.eventName == LibraryEvent.messageReceived || + libraryEvent.eventName == LibraryEvent.notificationTapped) { + callback(Message.fromJson(libraryEvent.payload)); + } else if (libraryEvent.eventName == + LibraryEvent.installationUpdated) { + callback(Installation.fromJson(libraryEvent.payload).toString()); + } else if (libraryEvent.eventName == LibraryEvent.userUpdated) { + callback(UserData.fromJson(libraryEvent.payload)); + } else if (libraryEvent.payload != null) { + callback(libraryEvent.payload); + } else { + callback(libraryEvent.eventName); + } + }); + } + }, + onError: (dynamic error) { + log('Received error: ${error.message}'); + }, + cancelOnError: true, + ); static Map?> callbacks = HashMap(); @@ -70,7 +77,7 @@ class InfobipMobilemessaging { static MessageStorage? _defaultMessageStorage; /// Subscribes to [LibraryEvent] to perform provided callback function. - static Future on(String eventName, Function callback) async { + static void on(String eventName, Function callback) { if (callbacks.containsKey(eventName)) { var existed = callbacks[eventName]; existed?.add(callback); @@ -82,7 +89,7 @@ class InfobipMobilemessaging { } /// Unregisters handler from [LibraryEvent]. - static Future unregister(String eventName, Function? callback) async { + static void unregister(String eventName, Function? callback) { if (callbacks.containsKey(eventName)) { var existed = callbacks[eventName]; existed?.remove(callback); @@ -93,7 +100,7 @@ class InfobipMobilemessaging { } /// Unsubscribes all handlers from given [LibraryEvent]. - static Future unregisterAllHandlers(String eventName) async { + static void unregisterAllHandlers(String eventName) { if (callbacks.containsKey(eventName)) { callbacks.removeWhere((key, value) => key == eventName); } @@ -106,13 +113,15 @@ class InfobipMobilemessaging { String str = await _getVersion(); configuration.pluginVersion = str; - await _channel.invokeMethod('init', jsonEncode(configuration.toJson())); + return await _channel.invokeMethod( + 'init', + jsonEncode(configuration.toJson()), + ); } /// Saves [UserData] to server. - static Future saveUser(UserData userData) async { - await _channel.invokeMethod('saveUser', jsonEncode(userData.toJson())); - } + static Future saveUser(UserData userData) async => + await _channel.invokeMethod('saveUser', jsonEncode(userData.toJson())); /// Asynchronously fetches [UserData] from server. static Future fetchUser() async => @@ -123,34 +132,33 @@ class InfobipMobilemessaging { UserData.fromJson(jsonDecode(await _channel.invokeMethod('getUser'))); /// Asynchronously saves [Installation] data to server. - static Future saveInstallation(Installation installation) async { - await _channel.invokeMethod( - 'saveInstallation', - jsonEncode(installation.toJson()), - ); - } + static Future saveInstallation(Installation installation) async => + await _channel.invokeMethod( + 'saveInstallation', + jsonEncode(installation.toJson()), + ); /// Asynchronously fetches [Installation] from server. static Future fetchInstallation() async => Installation.fromJson( - jsonDecode(await _channel.invokeMethod('fetchInstallation'))); + jsonDecode(await _channel.invokeMethod('fetchInstallation')), + ); /// Asynchronously gets [Installation] data from local data. static Future getInstallation() async => Installation.fromJson( - jsonDecode(await _channel.invokeMethod('getInstallation'))); + jsonDecode(await _channel.invokeMethod('getInstallation')), + ); /// Asynchronously personalizes current [Installation] with a Person profile on the server. /// For more information and examples see: Users and installations - static Future personalize(PersonalizeContext context) async { - await _channel.invokeMethod('personalize', jsonEncode(context.toJson())); - } + static Future personalize(PersonalizeContext context) async => + await _channel.invokeMethod('personalize', jsonEncode(context.toJson())); /// Asynchronously erases currently stored `User` on SDK and server associated /// with push registration, along with messages in SDK storage (also, deletes /// data for chat module). - static void depersonalize() async { - await _channel.invokeMethod('depersonalize'); - } + static Future depersonalize() async => + await _channel.invokeMethod('depersonalize'); /// Asynchronously cleans up all persisted data. /// This method deletes SDK data related to current application code (also, @@ -159,21 +167,23 @@ class InfobipMobilemessaging { /// Application Codes during development/testing, in this case you should /// manually invoke [cleanup]. After cleanup, you should call [init] with a /// new Application Code in order to use library again. - static Future cleanup() async { - await _channel.invokeMethod('cleanup'); - } + static Future cleanup() async => await _channel.invokeMethod('cleanup'); /// Asynchronously depersonalizes given `pushRegistrationId` from user. - static void depersonalizeInstallation(String pushRegistrationId) async { - await _channel.invokeMethod( - 'depersonalizeInstallation', pushRegistrationId); - } + static Future depersonalizeInstallation( + String pushRegistrationId, + ) async => + await _channel.invokeMethod( + 'depersonalizeInstallation', + pushRegistrationId, + ); /// Asynchronously configures provided device as primary among others devices /// of a single user. Will return list of installations only when list changes: /// if current installation is set as primary or already a primary one, will return null. static Future?> setInstallationAsPrimary( - InstallationPrimary installationPrimary) async { + InstallationPrimary installationPrimary, + ) async { String str = await _channel.invokeMethod( 'setInstallationAsPrimary', installationPrimary.toJson(), @@ -181,27 +191,31 @@ class InfobipMobilemessaging { if (str != 'Success') { Iterable l = json.decode(str); return List.from( - l.map((model) => Installation.fromJson(model))); + l.map((model) => Installation.fromJson(model)), + ); } return null; } /// Shows chat screen. - static Future showChat( - {bool shouldBePresentedModallyIOS = true}) async { - await _channel.invokeMethod('showChat', shouldBePresentedModallyIOS); - } + static Future showChat({ + bool shouldBePresentedModallyIOS = true, + }) async => + await _channel.invokeMethod('showChat', shouldBePresentedModallyIOS); /// Sets chat customization. - static Future setChatCustomization(Object settings) async { - await _channel.invokeMethod('setChatCustomization', jsonEncode(settings)); - } + static Future setChatCustomization(Object settings) async => + await _channel.invokeMethod('setChatCustomization', jsonEncode(settings)); - @deprecated + @Deprecated( + "setupiOSChatSettings is deprecated. Please use setChatCustomization instead", + ) static Future setupiOSChatSettings(IOSChatSettings settings) async { if (Platform.isIOS) { - await _channel.invokeMethod( - 'setupiOSChatSettings', jsonEncode(settings.toJson())); + return await _channel.invokeMethod( + 'setupiOSChatSettings', + jsonEncode(settings.toJson()), + ); } } @@ -209,17 +223,18 @@ class InfobipMobilemessaging { /// event should be registered by definition ID and optional properties in Portal. /// In case of validation or network issues error will be returned and you'd /// need to manually retry sending of the event. - static void submitEvent(Object customEvent) { - _channel.invokeMethod('submitEvent', jsonEncode(customEvent)); - } + static Future submitEvent(Object customEvent) async => + await _channel.invokeMethod('submitEvent', jsonEncode(customEvent)); /// Asynchronously submits custom events without validation. Custom event /// should be registered by definition ID and optional properties in in Portal. /// Validation will not be performed. If wrong definition is provided event /// will be considered as invalid and won't be visible on user. - static void submitEventImmediately(Object customEvent) { - _channel.invokeMethod('submitEventImmediately', jsonEncode(customEvent)); - } + static Future submitEventImmediately(Object customEvent) async => + await _channel.invokeMethod( + 'submitEventImmediately', + jsonEncode(customEvent), + ); /// Returns current unread chat push message counter. static Future getMessageCounter() async => @@ -227,44 +242,44 @@ class InfobipMobilemessaging { /// Resets current unread chat push message counter to zero. /// MobileMessaging automatically resets the counter when chat is opened. - static void resetMessageCounter() async { - await _channel.invokeMethod('resetMessageCounter'); - } + static Future resetMessageCounter() async => + await _channel.invokeMethod('resetMessageCounter'); /// Sets the language of the widget, in locale format e.g.: `en-US` - static void setLanguage(String language) async { - await _channel.invokeMethod('setLanguage', language); - } + static Future setLanguage(String language) async => + await _channel.invokeMethod('setLanguage', language); /// Sets the theme of the Livechat widget. - static setWidgetTheme(String widgetTheme) async { - await _channel.invokeMethod('setWidgetTheme', widgetTheme); - } + static setWidgetTheme(String widgetTheme) async => + await _channel.invokeMethod('setWidgetTheme', widgetTheme); /// Sends contextual data of the Livechat Widget. @deprecated - static void sendContextualData( - String data, bool allMultiThreadStrategy - ) async { - InfobipMobilemessaging.sendContextualDataWithStrategy( - data, - allMultiThreadStrategy ? ChatMultithreadStrategies.all : ChatMultithreadStrategies.active - ); - } + static Future sendContextualData( + String data, + bool allMultiThreadStrategy, + ) async => + await InfobipMobilemessaging.sendContextualDataWithStrategy( + data, + allMultiThreadStrategy + ? ChatMultithreadStrategies.all + : ChatMultithreadStrategies.active, + ); /// Sends contextual data of the Livechat Widget. - static void sendContextualDataWithStrategy( - String data, [ChatMultithreadStrategies chatMultithreadStrategy = ChatMultithreadStrategies.active] - ) async { - await _channel.invokeMethod('sendContextualData', - {'data': data, 'chatMultiThreadStrategy': chatMultithreadStrategy.stringValue } - ); - } + static Future sendContextualDataWithStrategy( + String data, [ + ChatMultithreadStrategies chatMultithreadStrategy = + ChatMultithreadStrategies.active, + ]) async => + await _channel.invokeMethod('sendContextualData', { + 'data': data, + 'chatMultiThreadStrategy': chatMultithreadStrategy.stringValue + }); /// Sets JWT for Livechat. - static void setJwt(String jwt) async { - await _channel.invokeMethod('setJwt', jwt); - } + static Future setJwt(String jwt) async => + await _channel.invokeMethod('setJwt', jwt); static MessageStorage? defaultMessageStorage() { if (_configuration == null) { @@ -289,7 +304,7 @@ class InfobipMobilemessaging { return; } - await _channel.invokeMethod('registerForAndroidRemoteNotifications'); + return await _channel.invokeMethod('registerForAndroidRemoteNotifications'); } /// Shows dialog to user to receive push notifications on iOS devices. @@ -299,27 +314,24 @@ class InfobipMobilemessaging { return; } - await _channel.invokeMethod('registerForRemoteNotifications'); + return await _channel.invokeMethod('registerForRemoteNotifications'); } - static Future enableCalls(String identity) async { - await _channel.invokeMethod('enableCalls', identity); - } + static Future enableCalls(String identity) async => + await _channel.invokeMethod('enableCalls', identity); - static Future enableChatCalls() async { - await _channel.invokeMethod('enableChatCalls'); - } + static Future enableChatCalls() async => + await _channel.invokeMethod('enableChatCalls'); - static Future disableCalls() async { - await _channel.invokeMethod('disableCalls'); - } + static Future disableCalls() async => + await _channel.invokeMethod('disableCalls'); static Future restartConnection() async { if (!Platform.isIOS) { log("It's supported only on the iOS platform"); return; } - await _channel.invokeMethod('restartConnection'); + return await _channel.invokeMethod('restartConnection'); } static Future stopConnection() async { @@ -327,7 +339,7 @@ class InfobipMobilemessaging { log("It's supported only on the iOS platform"); return; } - await _channel.invokeMethod('stopConnection'); + return await _channel.invokeMethod('stopConnection'); } /// Fetches messages from Inbox. @@ -337,16 +349,22 @@ class InfobipMobilemessaging { /// ```dart /// var inbox = await fetchInboxMessages('jwtToken', 'yourId', FilterOptions()); static Future fetchInboxMessages( - String token, String externalUserId, FilterOptions filterOptions) async { - return Inbox.fromJson(jsonDecode(await _channel.invokeMethod( - 'fetchInboxMessages', - { - 'token': token, - 'externalUserId': externalUserId, - 'filterOptions': jsonEncode(filterOptions.toJson()), - }, - ))); - } + String token, + String externalUserId, + FilterOptions filterOptions, + ) async => + Inbox.fromJson( + jsonDecode( + await _channel.invokeMethod( + 'fetchInboxMessages', + { + 'token': token, + 'externalUserId': externalUserId, + 'filterOptions': jsonEncode(filterOptions.toJson()), + }, + ), + ), + ); /// Fetches messages from [Inbox] without token - recommended only for sandbox /// applications. For production apps use [fetchInboxMessages] with token. @@ -356,51 +374,56 @@ class InfobipMobilemessaging { /// ```dart /// var inbox = await fetchInboxMessagesWithoutToken('yourId', FilterOptions()); static Future fetchInboxMessagesWithoutToken( - String externalUserId, FilterOptions filterOptions) async { - return Inbox.fromJson(jsonDecode(await _channel.invokeMethod( - 'fetchInboxMessagesWithoutToken', - { - 'externalUserId': externalUserId, - 'filterOptions': jsonEncode(filterOptions.toJson()), - }, - ))); - } + String externalUserId, + FilterOptions filterOptions, + ) async => + Inbox.fromJson( + jsonDecode( + await _channel.invokeMethod( + 'fetchInboxMessagesWithoutToken', + { + 'externalUserId': externalUserId, + 'filterOptions': jsonEncode(filterOptions.toJson()), + }, + ), + ), + ); /// Sets [Inbox] messages as seen. /// Requires externalUserId and List of IDs of messages to be marked as seen. static Future setInboxMessagesSeen( - String externalUserId, List messageIds) async { - await _channel.invokeMethod( - 'setInboxMessagesSeen', - { - 'externalUserId': externalUserId, - 'messageIds': messageIds, - }, - ); - } + String externalUserId, + List messageIds, + ) async => + await _channel.invokeMethod( + 'setInboxMessagesSeen', + { + 'externalUserId': externalUserId, + 'messageIds': messageIds, + }, + ); - static Future markMessagesSeen(List messageIds) async { - await _channel.invokeMethod('markMessagesSeen', messageIds); - } + static Future markMessagesSeen(List messageIds) async => + await _channel.invokeMethod('markMessagesSeen', messageIds); /// Sets title for in-app chat notifications and overrides default values. /// Supported only on Android. - static void setChatPushTitle(String? title) async { + static Future setChatPushTitle(String? title) async { if (!Platform.isAndroid) { log("It's supported only on the Android platform"); return; } - await _channel.invokeMethod('setChatPushTitle', title); + return await _channel.invokeMethod('setChatPushTitle', title); } /// Sets body for in-app chat notifications and overrides default values. /// Supported only on Android. - static void setChatPushBody(String? body) async { + static Future setChatPushBody(String? body) async { if (!Platform.isAndroid) { log("It's supported only on the Android platform"); return; } - await _channel.invokeMethod('setChatPushBody', body); + return await _channel.invokeMethod('setChatPushBody', body); } /// Used by MobileMessaging plugin to get plugin's version. @@ -411,7 +434,9 @@ class InfobipMobilemessaging { if (fileContent.isNotEmpty) { String versionStr = fileContent.substring( - fileContent.indexOf('version:'), fileContent.indexOf('\nhomepage:')); + fileContent.indexOf('version:'), + fileContent.indexOf('\nhomepage:'), + ); versionStr = versionStr.substring(9, versionStr.length); return versionStr.trim(); } diff --git a/lib/models/chat/chat_view.dart b/lib/models/chat/chat_view.dart index e119d6c..df7c75d 100644 --- a/lib/models/chat/chat_view.dart +++ b/lib/models/chat/chat_view.dart @@ -7,12 +7,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:infobip_mobilemessaging/models/chat/chat_view_attachment.dart'; -import 'package:infobip_mobilemessaging/models/chat/chat_view_event.dart'; -import 'package:infobip_mobilemessaging/models/chat/widget_info.dart'; +import 'chat_view_attachment.dart'; +import 'chat_view_event.dart'; +import 'widget_info.dart'; typedef FlutterChatViewCreatedCallback = void Function( - ChatViewController controller); + ChatViewController controller, +); class ChatView extends StatelessWidget { static const StandardMessageCodec _decoder = StandardMessageCodec(); @@ -30,8 +31,8 @@ class ChatView extends StatelessWidget { @override Widget build(BuildContext context) { Map args = {}; - if (this.withToolbar != null) args['withToolbar'] = this.withToolbar; - if (this.withInput != null) args['withInput'] = this.withInput; + if (withToolbar != null) args['withToolbar'] = withToolbar; + if (withInput != null) args['withInput'] = withInput; switch (defaultTargetPlatform) { case TargetPlatform.android: @@ -40,11 +41,11 @@ class ChatView extends StatelessWidget { onPlatformViewCreated: _onPlatformViewCreated, creationParams: args, creationParamsCodec: _decoder, - gestureRecognizers: [ - new Factory( - () => new EagerGestureRecognizer(), + gestureRecognizers: { + Factory( + () => EagerGestureRecognizer(), ), - ].toSet(), + }, ); case TargetPlatform.iOS: return UiKitView( @@ -52,15 +53,16 @@ class ChatView extends StatelessWidget { onPlatformViewCreated: _onPlatformViewCreated, creationParams: args, creationParamsCodec: _decoder, - gestureRecognizers: [ - new Factory( - () => new EagerGestureRecognizer(), + gestureRecognizers: { + Factory( + () => EagerGestureRecognizer(), ), - ].toSet(), + }, ); default: return Text( - '$defaultTargetPlatform is not yet supported by the infobip_mobilemessaging plugin'); + '$defaultTargetPlatform is not yet supported by the infobip_mobilemessaging plugin', + ); } } @@ -70,8 +72,11 @@ class ChatView extends StatelessWidget { class ChatViewController { ChatViewController._(int id) - : _channel = MethodChannel('infobip_mobilemessaging/flutter_chat_view_$id'), - _chatEvent = EventChannel('infobip_mobilemessaging/flutter_chat_view_$id/events') { + : _channel = + MethodChannel('infobip_mobilemessaging/flutter_chat_view_$id'), + _chatEvent = EventChannel( + 'infobip_mobilemessaging/flutter_chat_view_$id/events', + ) { _eventsSubscription = _chatEvent.receiveBroadcastStream().listen( (dynamic event) { log('[ChatViewController] Received event: $event'); @@ -79,9 +84,11 @@ class ChatViewController { if (_callbacks.containsKey(chatViewEvent.eventName)) { _callbacks[chatViewEvent.eventName]?.forEach((callback) { log('[ChatViewController] Calling ${chatViewEvent.eventName} with payload ${chatViewEvent.payload == null ? 'NULL' : chatViewEvent.payload.toString()}'); - if (chatViewEvent.eventName == ChatViewEvent.chatWidgetInfoUpdated) { + if (chatViewEvent.eventName == + ChatViewEvent.chatWidgetInfoUpdated) { callback(WidgetInfo.fromJson(chatViewEvent.payload)); - } else if (chatViewEvent.eventName == ChatViewEvent.attachmentPreviewOpened) { + } else if (chatViewEvent.eventName == + ChatViewEvent.attachmentPreviewOpened) { callback(ChatViewAttachment.fromJson(chatViewEvent.payload)); } else if (chatViewEvent.payload != null) { callback(chatViewEvent.payload); @@ -101,7 +108,7 @@ class ChatViewController { final MethodChannel _channel; final EventChannel _chatEvent; StreamSubscription? _eventsSubscription; - Map?> _callbacks = HashMap(); + final Map?> _callbacks = HashMap(); /// Navigates chat from [THREAD] back to [THREAD_LIST] destination in multithread chat. /// It does nothing if widget is not multithread. @@ -167,9 +174,8 @@ class ChatViewController { } /// Returns true if chat is synchronized and multithread feature is enabled, otherwise returns false. - Future isMultithread() async { - return await _channel.invokeMethod('isMultithread'); - } + Future isMultithread() async => + await _channel.invokeMethod('isMultithread'); /// Registers a callback for the given event name. /// [ChatViewEvent] class provides constants of all available events names diff --git a/lib/models/data/installation.dart b/lib/models/data/installation.dart index 8de12d9..62e68f5 100644 --- a/lib/models/data/installation.dart +++ b/lib/models/data/installation.dart @@ -1,3 +1,4 @@ +// ignore_for_file: constant_identifier_names import 'package:collection/collection.dart'; enum OS { Android, iOS } diff --git a/lib/models/data/personalize_context.dart b/lib/models/data/personalize_context.dart index 2a3dba0..42bb51e 100644 --- a/lib/models/data/personalize_context.dart +++ b/lib/models/data/personalize_context.dart @@ -26,7 +26,7 @@ class PersonalizeContext { this.userIdentity, this.userAttributes, this.forceDepersonalize, - this.keepAsLead + this.keepAsLead, }); Map toJson() => { diff --git a/lib/models/data/user_data.dart b/lib/models/data/user_data.dart index 87b1819..b0b8790 100644 --- a/lib/models/data/user_data.dart +++ b/lib/models/data/user_data.dart @@ -1,9 +1,11 @@ +// ignore_for_file: constant_identifier_names import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'installation.dart'; enum Gender { Male, Female } + enum Type { LEAD, CUSTOMER } class UserData { @@ -89,9 +91,12 @@ class UserData { installations = UserData.resolveInstallations(json['installations']); Map toJson() { - List? installations = this.installations != null - ? this.installations?.map((i) => i.toJson()).toList() - : null; + final List? installations; + if (this.installations != null) { + installations = this.installations?.map((i) => i.toJson()).toList(); + } else { + installations = null; + } return { 'externalUserId': externalUserId, diff --git a/lib/models/inbox/filter_options.dart b/lib/models/inbox/filter_options.dart index 1bc3942..04ca077 100644 --- a/lib/models/inbox/filter_options.dart +++ b/lib/models/inbox/filter_options.dart @@ -34,4 +34,11 @@ class FilterOptions { toDateTime == other.toDateTime && topic == other.topic && limit == other.limit; + + @override + int get hashCode => + fromDateTime.hashCode ^ + toDateTime.hashCode ^ + topic.hashCode ^ + limit.hashCode; } diff --git a/lib/models/message_storage/default_message_storage.dart b/lib/models/message_storage/default_message_storage.dart index eb36771..1a9f33f 100644 --- a/lib/models/message_storage/default_message_storage.dart +++ b/lib/models/message_storage/default_message_storage.dart @@ -21,8 +21,11 @@ class DefaultMessageStorage extends MessageStorage { } @override - Future find(String messageId) async => Message.fromJson(jsonDecode( - await _channel.invokeMethod('defaultMessageStorage_find', messageId))); + Future find(String messageId) async => Message.fromJson( + jsonDecode( + await _channel.invokeMethod('defaultMessageStorage_find', messageId), + ), + ); @override Future?> findAll() async { diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index 0875455..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,205 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - characters: - dependency: transitive - description: - name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - clock: - dependency: transitive - description: - name: clock - sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.dev" - source: hosted - version: "1.1.1" - collection: - dependency: "direct main" - description: - name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" - fake_async: - dependency: transitive - description: - name: fake_async - sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" - url: "https://pub.dev" - source: hosted - version: "1.3.1" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_lints: - dependency: "direct dev" - description: - name: flutter_lints - sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1" - url: "https://pub.dev" - source: hosted - version: "3.0.2" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - leak_tracker: - dependency: transitive - description: - name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" - url: "https://pub.dev" - source: hosted - version: "10.0.0" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - leak_tracker_testing: - dependency: transitive - description: - name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - lints: - dependency: transitive - description: - name: lints - sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 - url: "https://pub.dev" - source: hosted - version: "3.0.0" - matcher: - dependency: transitive - description: - name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb - url: "https://pub.dev" - source: hosted - version: "0.12.16+1" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" - url: "https://pub.dev" - source: hosted - version: "0.8.0" - meta: - dependency: transitive - description: - name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 - url: "https://pub.dev" - source: hosted - version: "1.11.0" - path: - dependency: transitive - description: - name: path - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" - url: "https://pub.dev" - source: hosted - version: "1.9.0" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" - url: "https://pub.dev" - source: hosted - version: "1.10.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" - url: "https://pub.dev" - source: hosted - version: "1.11.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 - url: "https://pub.dev" - source: hosted - version: "2.1.2" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" - source: hosted - version: "1.2.1" - test_api: - dependency: transitive - description: - name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" - url: "https://pub.dev" - source: hosted - version: "0.6.1" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 - url: "https://pub.dev" - source: hosted - version: "13.0.0" -sdks: - dart: ">=3.2.0-0 <4.0.0" - flutter: ">=3.3.0" diff --git a/pubspec.yaml b/pubspec.yaml index 21394af..f0ae290 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,12 +12,12 @@ environment: dependencies: flutter: sdk: flutter - collection: ^1.17.0 + collection: ^1.16.0 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^3.0.2 + flutter_lints: ^2.0.2 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/test/infobip_mobilemessaging_test.dart b/test/infobip_mobilemessaging_test.dart index cbd44f9..d7b701d 100644 --- a/test/infobip_mobilemessaging_test.dart +++ b/test/infobip_mobilemessaging_test.dart @@ -5,7 +5,8 @@ import 'package:infobip_mobilemessaging/models/configurations/configuration.dart void main() { const MethodChannel infobipChannel = MethodChannel('infobip_mobilemessaging'); - const MethodChannel packageInfoChannel = MethodChannel('dev.fluttercommunity.plus/package_info'); + const MethodChannel packageInfoChannel = + MethodChannel('dev.fluttercommunity.plus/package_info'); TestWidgetsFlutterBinding.ensureInitialized(); @@ -40,20 +41,22 @@ void main() { }); test('init', () async { - await InfobipMobilemessaging.init(Configuration( + await InfobipMobilemessaging.init( + Configuration( applicationCode: "", androidSettings: AndroidSettings( - firebaseOptions: FirebaseOptions( - apiKey: "Some-API-Key", - applicationId: "1:1234567890:android:abc123", - projectId: "project-123ab" - ), + firebaseOptions: FirebaseOptions( + apiKey: "Some-API-Key", + applicationId: "1:1234567890:android:abc123", + projectId: "project-123ab", + ), ), iosSettings: IOSSettings( - notificationTypes: ["alert", "badge", "sound"], - forceCleanup: false, - logging: true - ) - )); + notificationTypes: ["alert", "badge", "sound"], + forceCleanup: false, + logging: true, + ), + ), + ); }); -} \ No newline at end of file +} diff --git a/test/json_test.dart b/test/json_test.dart index e34e3e4..42cb8f6 100644 --- a/test/json_test.dart +++ b/test/json_test.dart @@ -17,8 +17,10 @@ void main() { }); test('InstallationPrimary', () { - expect(installationPrimaryModelExample.toJson(), - installationPrimaryExampleJson); + expect( + installationPrimaryModelExample.toJson(), + installationPrimaryExampleJson, + ); }); test('UserIdentity', () { @@ -26,8 +28,10 @@ void main() { }); test('PersonalizeContext', () { - expect(personalizeContextModelExample.toJson(), - personalizeContextExampleJson); + expect( + personalizeContextModelExample.toJson(), + personalizeContextExampleJson, + ); }); test('UserData', () { @@ -41,8 +45,10 @@ void main() { }); test('Installation', () { - expect(Installation.fromJson(installationExampleJson), - installationModelExample); + expect( + Installation.fromJson(installationExampleJson), + installationModelExample, + ); }); test('UserData', () { diff --git a/test/utils/models_examples.dart b/test/utils/models_examples.dart index c02a85b..e5b55cd 100644 --- a/test/utils/models_examples.dart +++ b/test/utils/models_examples.dart @@ -10,31 +10,38 @@ Configuration get configurationModelExample => Configuration( inAppChatEnabled: true, fullFeaturedInAppsEnabled: true, androidSettings: AndroidSettings( - firebaseOptions: FirebaseOptions( - apiKey: "Some-API-Key", - applicationId: "1:1234567890:android:abc123", - projectId: "project-123ab"), - notificationIcon: 'icon.png', - multipleNotifications: true, - notificationAccentColor: "#ABCDEF"), + firebaseOptions: FirebaseOptions( + apiKey: "Some-API-Key", + applicationId: "1:1234567890:android:abc123", + projectId: "project-123ab", + ), + notificationIcon: 'icon.png', + multipleNotifications: true, + notificationAccentColor: "#ABCDEF", + ), iosSettings: IOSSettings( - notificationTypes: ['sound'], - forceCleanup: true, - logging: true, - withoutRegisteringForRemoteNotifications: true, - webViewSettings: WebViewSettings( - title: 'webViewTitle', - barTintColor: '#012345', - titleColor: '#135', - tintColor: '#246')), + notificationTypes: ['sound'], + forceCleanup: true, + logging: true, + withoutRegisteringForRemoteNotifications: true, + webViewSettings: WebViewSettings( + title: 'webViewTitle', + barTintColor: '#012345', + titleColor: '#135', + tintColor: '#246', + ), + ), privacySettings: PrivacySettings( - applicationCodePersistingDisabled: true, - userDataPersistingDisabled: true, - carrierInfoSendingDisabled: true, - systemInfoSendingDisabled: true), + applicationCodePersistingDisabled: true, + userDataPersistingDisabled: true, + carrierInfoSendingDisabled: true, + systemInfoSendingDisabled: true, + ), notificationCategories: [ - NotificationCategory(identifier: '123', actions: [ - NotificationAction( + NotificationCategory( + identifier: '123', + actions: [ + NotificationAction( identifier: '123456', title: 'Action Title', foreground: true, @@ -43,8 +50,10 @@ Configuration get configurationModelExample => Configuration( destructive: true, icon: 'icon-action.png', textInputActionButtonTitle: 'Button Title', - textInputPlaceholder: 'Placeholder Title') - ]) + textInputPlaceholder: 'Placeholder Title', + ) + ], + ) ], defaultMessageStorage: true, );