• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Asset Profile Operations

This example shows:

  • Create an Asset: Create a new asset with a custom ID, name, description, and attributes. The created asset ID is stored in the assetTracking object.
  • Bind an Asset ID: Bind an existing asset ID to the current session. This action associates the current session with a specific asset.
  • Update Current Asset Profile: Update the profile of the current asset. Change the name, description, and attributes of the asset.
  • Retrieve Asset Detail of Current Asset ID: Retrieve detailed information about the current asset, such as its ID, name, description, and attributes.

asset_profile_screen.dart view source

1import 'dart:convert';
2
3import 'package:flutter/material.dart';
4import 'package:nb_asset_tracking_flutter/nb_asset_tracking_flutter.dart';
5import 'package:nb_asset_tracking_flutter_example/util/consts.dart';
6import 'package:nb_asset_tracking_flutter_example/util/toast_mixin.dart';
7import 'package:uuid/uuid.dart';
8
9class AssetProfileScreen extends StatefulWidget {
10
11 AssetProfileScreenState createState() => new AssetProfileScreenState();
12}
13
14class AssetProfileScreenState extends State<AssetProfileScreen> with ToastMixin {
15 final assetTracking = AssetTracking();
16 String assetId = "";
17 String assetDetailInfo = "";
18

Here are the code highlights for each of the four functionalities:

Create an Asset: assetTracking.createAsset(profile: profile)

  1. This functionality is implemented within the onPressed callback of the "Create New Asset" button.
  2. It creates a new AssetProfile object with a custom ID, name, description, and empty attributes.
  3. The createAsset method of the assetTracking object is called to create the asset.
  4. If the operation is successful (result.success), the asset ID is stored (assetId = result.data), and a success message is displayed. Otherwise, an error message is shown.

Bind an Asset ID: assetTracking.bindAsset(customId: assetId)

  1. This functionality is implemented within the onPressed callback of the "Bind Asset" button.
  2. It calls the bindAsset method of the assetTracking object to bind the current asset ID.
  3. If the operation is successful (assetResult.success), a success message is displayed. Otherwise, an error message is shown.

Update Current Asset Profile: assetTracking.updateAsset(assetProfile: assetProfile)

  1. This functionality is implemented within the onPressed callback of the "Update Asset Info" button.
  2. It creates a new AssetProfile object with updated information (name, description, and attributes).
  3. The updateAsset method of the assetTracking object is called to update the asset profile.
  4. If the operation is successful (assetDetail.success), a success message is displayed. Otherwise, an error message is shown.

Retrieve Asset Detail of Current Asset ID: assetTracking.getAssetDetail()

  1. This functionality is implemented within the onPressed callback of the "Get Asset Detail" button.
  2. It calls the getAssetDetail method of the assetTracking object to retrieve detailed information about the current asset.
  3. If the operation is successful (assetDetail.success), the retrieved information is stored in assetDetailInfo and displayed on the screen. Otherwise, an error message is shown.

Have Questions ?