dependencies : sense_flutter_plugin : ^2.0.3import 'package:sense_flutter_plugin/sense_flutter_plugin.dart';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,
},
});
}metaInfo is optional and supports up to 15 key-value pairs; each key and value can contain up to 256 characters.| 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. |
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>>[],
},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");
}
}import 'dart:convert'; when decoding a JSON string response.import 'dart:async';
late final StreamSubscription<Map<dynamic, dynamic>> securitySubscription;
void initState() {
super.initState();
securitySubscription = Sense.securityEvents.listen((event) {
final type = event["type"];
final value = event["value"];
print("Security event: $type -> $value");
});
}
void dispose() {
securitySubscription.cancel();
super.dispose();
}flutter pub get
flutter run