Initialize SDK and get device details
To initialise the SDK add the below line of code with the public key you retrieved from Sense client panel. If you don't have a public key create new one and call that below function.
How to Install
  1. Add the SDK to your app's pubspec.yaml
    copy-icon
    dependencies : sense_flutter_plugin : ^2.0.3
  2. Import the SDK in Dart
    copy-icon
    import 'package:sense_flutter_plugin/sense_flutter_plugin.dart';
  3. 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.
    copy-icon
    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.
  4. Configuration arguments
    ArgumentDescription
    publicKeySense public API key. Required.
    senseInfoEnables Sense information in the response.
    allowGeoLocationAllows location-related signals when supported and permitted by the platform.
    tagApplication or integration label.
    sessionIdOptional identifier used for workflow integrations.
    metaInfoAdditional application-provided key-value data.
    optionalAdditional SDK-specific options.
    expectedAppSignaturesExpected Android app signatures for integrity validation.
    expectedPackageNameExpected Android application package name.
    sslPinningConfigCertificate pinning configuration for specific hosts.
    senseLogConfigSDK logging configuration. Keep logging disabled in production unless needed.
  5. 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:

    copy-icon
    "sslPinningConfig": {
      "enabled": false,
      "pinSets": <Map<String, dynamic>>[],
    },
  6. Get Device Details
    getSenseDetails() returns a response map containing success, message, and, on success, data.
    copy-icon
    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.
  7. Security events
    Subscribe to the security event stream to receive RASP and device security signals:
    copy-icon
    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();
    }
  8. Platform setup
    Run the normal Flutter dependency and build commands after adding the package:
    copy-icon
    flutter pub get
    flutter run
    Ensure the Android and iOS project settings required by the signals you enable are configured in the host application.