Sense Flutter SDK

Sense provides device intelligence and device security signals for Flutter applications.

Installation

Add the SDK to your app's pubspec.yaml:

dependencies:
  sense_flutter_plugin: ^2.0.3

Import the SDK in Dart:

import 'package:sense_flutter_plugin/sense_flutter_plugin.dart';

Initialize the SDK

Create a Sense instance and initialize it before requesting device details. A good place to do this is a StatefulWidget's initState method.

final Sense sense = Sense();

@override
void initState() {
  super.initState();

  sense.initSDK({
    "publicKey": "YOUR_PUBLIC_KEY",
    "senseInfo": true,
    "allowGeoLocation": false,
    "tag": "YOUR_APP_NAME",
    "sessionId": "", // Optional workflow/session identifier.
    "metaInfo": {
      "phone": "USER_PHONE",
      "name": "USER_NAME",
    },
    "optional": <String, dynamic>{},
    "expectedAppSignatures": <String>[],
    "expectedPackageName": "com.example.your_app",
    "sslPinningConfig": {
      "enabled": true,
      "pinSets": [
        {
          "host": "dummyjson.com",
          "pins": [
            "sha256//1kYlcCuXHofjS1hAFCOx21ULpPjNxh78MyOZ+EXFOQ=",
            "sha256/kIdp6NNEd8wsugYyyIYFsi1ylMCED3hZbSR8ZFsa/A4=",
            "sha256/mEflZT5enoR1FuXLgYYGqnVEoZvmf9c2bVBpiOjYQ0c=",
          ],
        },
      ],
    },
    "senseLogConfig": {
      "enable": false,
    },
  });
}

Replace the placeholder values with values from your Sense client configuration. The public key is required. metaInfo is optional and supports up to 15 key-value pairs; each key and value can contain up to 256 characters.

Configuration arguments

Argument Description
publicKey Sense public API key. Required.
senseInfo Enables Sense information in the response.
allowGeoLocation Allows location-related signals when supported and permitted by the platform.
tag Application or integration label.
sessionId Optional identifier used for workflow integrations.
metaInfo Additional application-provided key-value data.
optional Additional SDK-specific options.
expectedAppSignatures Expected Android app signatures for integrity validation.
expectedPackageName Expected Android application package name.
sslPinningConfig Certificate pinning configuration for specific hosts.
senseLogConfig SDK logging configuration. Keep logging disabled in production unless needed.

SSL pinning

Set sslPinningConfig.enabled to true only when every configured host has valid, current pins. Each pinSets entry contains an exact hostname and one or more SHA-256 public-key pins. Multiple pins allow a backup certificate during certificate rotation.

When a certificate or public key changes, update the pins before deploying the server certificate change. Incorrect or expired pins can block requests to the configured host.

Use an empty configuration when pinning is not required:

"sslPinningConfig": {
  "enabled": false,
  "pinSets": <Map<String, dynamic>>[],
},

Get device details

getSenseDetails() returns a response map containing success, message, and, on success, data.

Future<void> getDeviceDetails() async {
  final response = await sense.getSenseDetails();

  if (response is! Map || response["success"] != true) {
    final message = response is Map
        ? response["message"]?.toString() ?? "Unable to get device details"
        : "Invalid SDK response";
    throw StateError(message);
  }

  final rawData = response["data"];
  final deviceDetails = rawData is String ? jsonDecode(rawData) : rawData;

  if (deviceDetails is Map) {
    final senseId = deviceDetails["sense_id"];
    final requestId = deviceDetails["request_id"];
    print("Sense ID: $senseId");
    print("Request ID: $requestId");
  }
}

Add import 'dart:convert'; when decoding a JSON string response.

Security events

Subscribe to the security event stream to receive RASP and device security signals:

import 'dart:async';

late final StreamSubscription<Map<dynamic, dynamic>> securitySubscription;

@override
void initState() {
  super.initState();

  securitySubscription = Sense.securityEvents.listen((event) {
    final type = event["type"];
    final value = event["value"];
    print("Security event: $type -> $value");
  });
}

@override
void dispose() {
  securitySubscription.cancel();
  super.dispose();
}

Platform setup

Run the normal Flutter dependency and build commands after adding the package:

flutter pub get
flutter run

Ensure the Android and iOS project settings required by the signals you enable are configured in the host application.