ConnectyCube / connectycube-flutter-sdk-releases

ConnectyCube Flutter SDK Releases
7 stars 1 forks source link

Exception on CubeAttachment.fromJson() method #94

Closed pedrostick3 closed 1 year ago

pedrostick3 commented 1 year ago

Platform (use [x]) [x] Android [] iOS [] macOS [] Windows [] Web

Device info Manufacture: Google Model: Pixel 4 OS version: Android API 33

Describe the bug: Tried to use the method CubeAttachment.fromJson of line 227 on file connectycube_sdk-2.5.5/lib/src/chat/models/cube_message.dart and it explodes reporting this error: Unhandled Exception: type 'double' is not a subtype of type 'String' on line 233 size = json['size'] != null ? double.parse(json['size']) : null; inside that method and file.

Steps to Reproduce:

  1. Call CubeAttachment.fromJson();
  2. Error appears.

Logs:

E/flutter (28262): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'double' is not a subtype of type 'String'
E/flutter (28262): #0      new CubeAttachment.fromJson
cube_message.dart:233
E/flutter (28262): #1      ConnectyCubeUtility.getCubeMessageFromJson.<anonymous closure>
connectycube_utility.dart:50
E/flutter (28262): #2      MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
E/flutter (28262): #3      ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
E/flutter (28262): #4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
E/flutter (28262): #5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
E/flutter (28262): #6      new List.of (dart:core-patch/array_patch.dart:47:28)
E/flutter (28262): #7      ListIterable.toList (dart:_internal/iterable.dart:214:7)
E/flutter (28262): #8      ConnectyCubeUtility.getCubeMessageFromJson
connectycube_utility.dart:50
E/flutter (28262): #9      Message.initFromCubeMessage
message.dart:224
E/flutter (28262): #10     Group.getGroupHistory.<anonymous closure>
group.dart:341
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #11     Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #12     Group.getGroupHistory
group.dart:336
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #13     GroupsStore.getConnectyCubeGroupsHistory
groups.store.dart:274
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #14     AsyncAction.run
async_action.dart:28
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #15     _SplashScreenState._onLoginSuccess
splash_screen.dart:128
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #16     _SplashScreenState._loadPrefs.<anonymous closure>
splash_screen.dart:104
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #17     DeeplinkStore._setValue
deeplink.store.dart:71
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #18     AsyncAction.run
async_action.dart:28
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #19     DeeplinkStore._handleReceivedIntent
deeplink.store.dart:98
E/flutter (28262): <asynchronous suspension>
E/flutter (28262): #20     DeeplinkStore.initializations.<anonymous closure>
deeplink.store.dart:38
E/flutter (28262): <asynchronous suspension>
E/flutter (28262):

Actual result: Method CubeAttachment.fromJson() not working properly.

Expected behavior: Method CubeAttachment.fromJson() should work without throwing this Exception.

Additional info I fixed it by replacing line 233 size = json['size'] != null ? double.parse(json['size']) : null; with this line of code size = json['size'] == null ? null : (json['size'] is String) ? double.parse(json['size']) : (json['size'] is double) ? json['size'] : null;.

Hope it helped :) Please fix this bug and contact me when you merge this into a new package version so i can update it ;)

TatankaConCube commented 1 year ago

@pedrostick3 fixed in version 2.5.7, please check it and close this ticket if your issue was resolved. Thank you for reporting it.

pedrostick3 commented 1 year ago

Tested and it is fixed, thanks! :)