• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Update Asset Configurations

This example shows:

  • Initialize asset tracking: Initialize Asset tracking with necessary configurations such as API key, fake GPS configuration, and data tracking configuration.
  • Create and Bind Asset: Creates a new asset profile and binds it to the asset tracking service. Ensures that the asset is ready for tracking.
  • Update Data Tracking Configurations: Update data tracking configurations such as batch size, batch window, and storage size. This is achieved by creating a new DataTrackingConfig object and calling the setDataTrackingConfig() method of the asset tracking service.
  • Update Location Configurations: Update location tracking configurations such as tracking mode and smallest displacement. This is done by creating a new LocationConfig object and calling the updateLocationConfig() method of the asset tracking service.
  • Update Notification Configurations: Update notification configurations based on the platform (Android or iOS). For Android, it updates the Android notification configuration, for iOS, it updates the iOS notification configuration. These configurations include settings such as notification channel ID, notification channel name, and asset enable notification title.

update_tracking_configuration.dart view source

1import 'dart:convert';
2import 'dart:io';
3
4import 'package:flutter/material.dart';
5import 'package:nb_asset_tracking_flutter/nb_asset_tracking_flutter.dart';
6import 'package:nb_asset_tracking_flutter_example/util/consts.dart';
7import 'package:nb_asset_tracking_flutter_example/util/toast_mixin.dart';
8import 'package:uuid/uuid.dart';
9
10class UpdateConfigurationExample extends StatefulWidget {
11
12 UpdateConfigurationExampleState createState() => UpdateConfigurationExampleState();
13}
14
15class UpdateConfigurationExampleState extends State<UpdateConfigurationExample>
16 with ToastMixin
17 implements OnTrackingDataCallBack {
18 bool bindAsset = false;

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

  1. Initialize Asset Tracking

    1. assetTracking.initialize(apiKey: accessKey): Initializes asset tracking with the provided API key.
    2. assetTracking.setFakeGpsConfig(allow: true): Allows using fake GPS configurations.
    3. assetTracking.addDataListener(this): Adds a data listener to track data updates.
    4. assetTracking.setDataTrackingConfig(config: DataTrackingConfig(baseUrl: baseUrlStaging)): Sets data tracking configurations such as the base URL.
  2. Create and Bind Asset

    1. AssetProfile profile = AssetProfile(...): Defines the profile of the asset to be created.
    2. AssetResult result = await assetTracking.createAsset(profile: profile): Creates a new asset with the specified profile.
    3. var assetResult = await assetTracking.bindAsset(customId: assetID): Binds the created asset to the tracking service.
  3. Update Data Tracking Configurations

    1. var dataTrackingConfig = DataTrackingConfig(...): Defines the data tracking configurations to be updated.
    2. await assetTracking.setDataTrackingConfig(config: dataTrackingConfig): Updates the data tracking configurations.
    3. var dataTrackingConfigInfo = await assetTracking.getDataTrackingConfig(): Retrieves the updated data tracking configurations.
  4. Update Location Configurations

    1. var locationConfig = LocationConfig(...): Defines the location configurations to be updated.
    2. await assetTracking.updateLocationConfig(config: locationConfig): Updates the location tracking configurations.
    3. var locationConfigResult = await assetTracking.getLocationConfig(): Retrieves the updated location tracking configurations.
  5. Update Notification Configurations

    1. For Android:
      1. var androidNotificationConfig = AndroidNotificationConfig(...): Defines the Android notification configurations.
      2. assetTracking.setAndroidNotificationConfig(config: androidNotificationConfig);: Sets the Android notification configurations.
      3. var androidConfig = await assetTracking.getAndroidNotificationConfig();: Retrieves the updated Android notification configurations.
    2. For iOS:
      1. var iOSNotificationConfig = IOSNotificationConfig(...): Defines the iOS notification configurations.
      2. assetTracking.setIOSNotificationConfig(config: iOSNotificationConfig);: Sets the iOS notification configurations.
      3. var iosConfig = await assetTracking.getIOSNotificationConfig();: Retrieves the updated iOS notification configurations.

Have Questions ?