Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null issues in getDeviceService().getUserDevices(PageLink(1)) #3

Closed
Dmuldoraf opened this issue Jun 9, 2022 · 2 comments
Closed

Null issues in getDeviceService().getUserDevices(PageLink(1)) #3

Dmuldoraf opened this issue Jun 9, 2022 · 2 comments

Comments

@Dmuldoraf
Copy link

Hi,
I faced the following error, while try calling _tbClient.getDeviceService().getUserDevices(PageLink(1)):
E/flutter ( 5652): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<String, dynamic>' E/flutter ( 5652): #0 new Device.fromJson package:thingsboard_pe_client/…/model/device_models.dart:766 E/flutter ( 5652): #1 parseDevicePageData.<anonymous closure> package:thingsboard_pe_client/…/service/device_service.dart:8 E/flutter ( 5652): #2 dataFromJson.<anonymous closure> package:thingsboard_pe_client/…/page/page_data.dart:35 E/flutter ( 5652): #3 MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31) E/flutter ( 5652): #4 ListIterator.moveNext (dart:_internal/iterable.dart:342:26) E/flutter ( 5652): #5 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:206:27) E/flutter ( 5652): #6 new _GrowableList.of (dart:core-patch/growable_array.dart:153:28) E/flutter ( 5652): #7 new List.of (dart:core-patch/array_patch.dart:51:28)

While debugging, I recieved this:
in device_model.dart
deviceProfileIdIsNull

With the following runtime variables:
data

Most of the devices parameter are empty, because I created it just with the necessary params with the API.
How can I use the method _tbClient.getDeviceService().getUserDevices(PageLink(1)) with this kind of devices?

Best regards :)

@vvlladd28
Copy link
Member

Hi @Dmuldoraf,
This is an exciting issue. Can you tell in more detail which version of the TB platform is installed in the server where you connect the app? Because deviceProfileId is the required field.

@drausal
Copy link

drausal commented Aug 30, 2022

Ran into this issue as a "CUSTOMER_USER" not "TENANT_ADMIN" the fix was to check if its null

This was required for both deviceProfileId and deviceData

Device.fromJson(Map<String, dynamic> json)
       : tenantId = TenantId.fromJson(json['tenantId']),
         customerId = json['customerId'] != null
             ? CustomerId.fromJson(json['customerId'])
             : null,
         name = json['name'],
         type = json['type'],
         label = json['label'],
         deviceProfileId = json['deviceProfileId'] != null ? DeviceProfileId.fromJson(json['deviceProfileId']) : null,
         firmwareId = json['firmwareId'] != null
             ? OtaPackageId.fromJson(json['firmwareId'])
             : null,
         softwareId = json['softwareId'] != null
             ? OtaPackageId.fromJson(json['softwareId'])
             : null,
         deviceData = json['deviceData'] != null ? DeviceData.fromJson(json['deviceData']) : DeviceData(),
         externalId = json['externalId'] != null
             ? DeviceId.fromJson(json['externalId'])
             : null,
         super.fromJson(json);

Server: Ubuntu
TB Version: PE 3.4 
Flutter: 3.0.5
Dart: 2.17.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants