• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Full Asset Tracking Example

This example shows:

  • Initialize Asset Tracking: Initialize asset tracking by calling the initialize() method of the AssetTracking class with the appropriate API key.
  • Check Permissions and Start Tracking: Before starting tracking, the application checks for location permissions, especially on Android devices. It ensures proper permission before initiating tracking.
  • Add Listener for Asset Tracking Callback: The application adds a listener to receive updates from the asset tracking service. This includes tracking status updates and location data.
  • Switch Asset Tracking Mode: Users can switch between different tracking modes, such as active, balanced, passive, or custom. The application updates the location configuration accordingly based on the selected mode.
  • Change Notification Configurations: Users can configure notification settings to track start and stop events. These configurations are platform-specific and handled appropriately for Android and iOS devices.
  • Start and Stop Tracking: The application provides buttons to start and stop tracking based on user input. It ensures that tracking is only started when all necessary configurations are set.
  • Display Tracking Status and Location Information: The application displays the current tracking status and location information in real-time. Users can monitor the tracking process and view location details as they are received.
  • Create a New Asset: Users can create a new asset profile within the application. This functionality allows for the management of multiple assets and tracking them separately.

home_screen.dart view source

1import 'dart:io';
2
3import 'package:flutter/material.dart';
4import 'package:fluttertoast/fluttertoast.dart';
5import 'package:nb_asset_tracking_flutter/nb_asset_tracking_flutter.dart';
6import 'package:nb_asset_tracking_flutter_example/util/permiss_checker.dart';
7import 'package:nb_asset_tracking_flutter_example/util/toast_mixin.dart';
8import 'package:shared_preferences/shared_preferences.dart';
9
10import '../util/consts.dart';
11import 'create_asset.dart';
12
13class HomeScreen extends StatefulWidget {
14 const HomeScreen({super.key});
15
16
17 State<HomeScreen> createState() => _MyAppState();
18}

These functionalities collectively enable users to manage asset tracking within the application, including configuring settings, initiating tracking, receiving notifications, and viewing relevant information.

  1. Initialize Asset Tracking:

    1. The code initializes the asset tracking module using a specific API key. This likely involves connecting to an external service or setting up internal tracking mechanisms.
  2. Check Permissions and Start Tracking:

    1. It checks if the necessary permissions to access the device's location are granted. If not, it may prompt the user to grant these permissions.
    2. Once permissions are granted, the code initiates the asset-tracking process, which may involve starting a service or initiating location tracking.
  3. Add Listener for Asset Tracking Callback:

    1. A listener is set up to receive updates from the asset tracking module. This listener likely handles events such as tracking start, stop, location updates, or errors.
  4. Switch Asset Tracking Mode:

    1. Users can switch between different tracking modes, such as active, balanced, passive, or custom. Each mode likely adjusts how frequently location data is collected or the level of accuracy required.
  5. Change Notification Configurations:

    1. Users can configure whether to receive notifications for tracking start and stop events. This allows for customization of the user experience based on preferences.
  6. Start and Stop Tracking:

    1. Users can initiate or terminate the tracking process through the application's interface. This functionality likely interacts with the underlying tracking service or module to control its behavior.
  7. Display Tracking Status and Location Information:

    1. The application provides visual feedback to users regarding the current tracking status (e.g., whether tracking is active or inactive)。
    2. Location information may be displayed to users in real-time, including latitude, longitude, speed, and accuracy.
  • Initialize Asset Tracking

    • assetTracking.initialize(apiKey: accessKey);
    • Add Listener for Asset Tracking Callback
    • assetTracking.addDataListener(this);
  • Check Permissions and Start Tracking (Called from startTracking method)

    • var granted = await checkAndRequestLocationPermission();
    • assetTracking.startTracking();
    • Switch Asset Tracking Mode (Called from onChanged callbacks of RadioListTile widgets)
    • assetTracking.updateLocationConfig(config: LocationConfig.activeConfig());
    • assetTracking.updateLocationConfig(config: LocationConfig.balancedConfig());
    • assetTracking.updateLocationConfig(config: LocationConfig.passiveConfig());
    • assetTracking.updateLocationConfig(config: LocationConfig());
  • Change Notification Configurations (Called from configNotificationConfig method)

    • assetTracking.setIOSNotificationConfig(config: iosNotificationConfig);
  • Start and Stop Tracking (Called from startTracking and stopTracking methods)

    • assetTracking.startTracking();
    • assetTracking.stopTracking();

Have Questions ?