Update thingsboard client library

This commit is contained in:
Igor Kulikov
2021-06-24 19:21:53 +03:00
parent f25888e5f6
commit 2187211f00
10 changed files with 35 additions and 25 deletions

View File

@@ -256,8 +256,7 @@ class TbContext {
log.debug('authUser: ${tbClient.getAuthUser()}');
if (tbClient.getAuthUser()!.userId != null) {
try {
userDetails = await tbClient.getUserService().getUser(
tbClient.getAuthUser()!.userId!);
userDetails = await tbClient.getUserService().getUser();
homeDashboard = await tbClient.getDashboardService().getHomeDashboardInfo();
} catch (e) {
tbClient.logout();

View File

@@ -46,7 +46,7 @@ abstract class EntityDetailsPage<T extends BaseData> extends TbPageWidget<Entity
@override
_EntityDetailsPageState createState() => _EntityDetailsPageState();
Future<T> fetchEntity(String id);
Future<T?> fetchEntity(String id);
ValueNotifier<String>? detailsTitle() {
return null;
@@ -58,7 +58,7 @@ abstract class EntityDetailsPage<T extends BaseData> extends TbPageWidget<Entity
class _EntityDetailsPageState<T extends BaseData> extends TbPageState<EntityDetailsPage<T>, _EntityDetailsPageState<T>> {
late Future<T> entityFuture;
late Future<T?> entityFuture;
late ValueNotifier<String> titleValue;
@override
@@ -112,12 +112,16 @@ class _EntityDetailsPageState<T extends BaseData> extends TbPageState<EntityDeta
},
),
),
body: FutureBuilder<T>(
body: FutureBuilder<T?>(
future: entityFuture,
builder: (context, snapshot) {
if (snapshot.hasData) {
var entity = snapshot.data!;
return widget.buildEntityDetails(context, entity);
if (snapshot.connectionState == ConnectionState.done) {
var entity = snapshot.data;
if (entity != null) {
return widget.buildEntityDetails(context, entity);
} else {
return Center(child: Text('Requested entity does not exists.'));
}
} else {
return Center(child: TbProgressIndicator(
size: 50.0,

View File

@@ -278,7 +278,7 @@ class _AlarmCardState extends TbContextState<AlarmCard, _AlarmCardState> {
alarm.id!.id!);
setState(() {
loading = false;
this.alarm = newAlarm;
this.alarm = newAlarm!;
});
}
}
@@ -294,7 +294,7 @@ class _AlarmCardState extends TbContextState<AlarmCard, _AlarmCardState> {
alarm.id!.id!);
setState(() {
loading = false;
this.alarm = newAlarm;
this.alarm = newAlarm!;
});
}
}

View File

@@ -12,7 +12,7 @@ class AssetDetailsPage extends EntityDetailsPage<AssetInfo> {
defaultTitle: 'Asset', subTitle: 'Asset details');
@override
Future<AssetInfo> fetchEntity(String assetId) {
Future<AssetInfo?> fetchEntity(String assetId) {
return tbClient.getAssetService().getAssetInfo(assetId);
}

View File

@@ -8,7 +8,7 @@ class CustomerDetailsPage extends ContactBasedDetailsPage<Customer> {
super(tbContext, entityId: customerId, defaultTitle: 'Customer', subTitle: 'Customer details');
@override
Future<Customer> fetchEntity(String customerId) {
Future<Customer?> fetchEntity(String customerId) {
return tbClient.getCustomerService().getCustomer(customerId);
}

View File

@@ -12,7 +12,7 @@ class DeviceDetailsPage extends EntityDetailsPage<DeviceInfo> {
defaultTitle: 'Device');
@override
Future<DeviceInfo> fetchEntity(String deviceId) {
Future<DeviceInfo?> fetchEntity(String deviceId) {
return tbClient.getDeviceService().getDeviceInfo(deviceId);
}

View File

@@ -140,7 +140,7 @@ class _ProfilePageState extends TbPageState<ProfilePage, _ProfilePageState> {
Future<void> _loadUser() async {
_isLoadingNotifier.value = true;
_currentUser = await tbClient.getUserService().getUser(tbClient.getAuthUser()!.userId!);
_currentUser = await tbClient.getUserService().getUser();
_setUser();
_isLoadingNotifier.value = false;
}

View File

@@ -8,7 +8,7 @@ class TenantDetailsPage extends ContactBasedDetailsPage<Tenant> {
super(tbContext, entityId: tenantId, defaultTitle: 'Tenant', subTitle: 'Tenant details');
@override
Future<Tenant> fetchEntity(String tenantId) {
Future<Tenant?> fetchEntity(String tenantId) {
return tbClient.getTenantService().getTenant(tenantId);
}

View File

@@ -8,8 +8,8 @@ abstract class DeviceProfileCache {
var deviceProfile = _cache[name];
if (deviceProfile == null) {
var device = await tbClient.getDeviceService().getDevice(deviceId);
deviceProfile = await tbClient.getDeviceProfileService().getDeviceProfileInfo(device.deviceProfileId!.id!);
_cache[name] = deviceProfile;
deviceProfile = await tbClient.getDeviceProfileService().getDeviceProfileInfo(device!.deviceProfileId!.id!);
_cache[name] = deviceProfile!;
}
return deviceProfile;
}