LogDrop Flutter SDK

Installation

Minimum Requirements:

  • Android 6.0
  • iOS 14.0
flutter pub add logdrop_flutter_sdk

Integration

Android

Edit your android/build.gradle

allprojects {
    ...
    repositories {
        ...
        maven {
            url = uri("https://artifactory.logdrop.io/repository/android-logdrop-sdk/")
        }
    }
}

Edit your android/app/build.gradle

 android {
    ...
    defaultConfig {
        buildConfigField("String", "LOGDROP_BASE_URL", "YOUR_SERVER_URL")
        buildConfigField("String", "LOGDROP_API_KEY", "YOUR_API_KEY")
        buildConfigField("boolean", "LOGDROP_LOGCAT_ENABLED", "true")
        buildConfigField("String", "LOGDROP_SENSITIVE_PATTERNS", "\"[]\"")
    }
}

Edit your YourApp.kt file in the Android module of your Flutter project as follows

import android.app.Application
import com.logdrop_flutter_sdk.LogDropFlutter
import org.json.JSONArray

class YourApp : Application() {
    override fun onCreate() {
        super.onCreate()
        //Add this
        LogDropFlutter.initLogDrop(
            logcatEnabled = BuildConfig.LOGDROP_LOGCAT_ENABLED,
            apiKey = BuildConfig.LOGDROP_API_KEY,
            baseUrl = BuildConfig.LOGDROP_BASE_URL,
            sensitiveInfoPatterns = JSONArray(BuildConfig.LOGDROP_SENSITIVE_PATTERNS).let { jsonArray ->
                List(jsonArray.length()) { index -> jsonArray.getString(index) }
            },
            context = this.applicationContext
        )
    }
}

iOS

Add the following keys to your Info.plist file:


<key>LogDropBaseUrl</key>
<string>YOUR_API_URL</string>

<key>LogDropApiKey</key>
<string>YOUR_API_KEY</string>

<key>LogDropLoggingEnabled</key>
<true/>

Update AppDelegate.swift


import Flutter
import UIKit
import logdrop_flutter_sdk

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      let infoDict = Bundle.main.infoDictionary
      let apiKey = infoDict?["LogDropApiKey"] as? String ?? ""
      let baseUrl = infoDict?["LogDropBaseUrl"] as? String ?? ""
      let loggingEnabled = infoDict?["LogDropLoggingEnabled"] as? Bool ?? true
      let sensitivePatterns = infoDict?["LogDropSensitivePatterns"] as? [String] ?? []

      LogDropFlutter.initialize(
        apiKey: apiKey,
        baseUrl: baseUrl,
        loggingEnabled: loggingEnabled,
        sensitivePatterns: sensitivePatterns
      )

      GeneratedPluginRegistrant.register(with: self)
      return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}


Usage

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:logdrop_flutter_sdk/logdropsdk.dart';

void main() async {
  runZonedGuarded(
        () async {
      WidgetsFlutterBinding.ensureInitialized();
      runApp(const MyApp());
    },
        (error, stackTrace) async {
      await LogDrop.crashTracker.handleRunZoneGuardedError(error, stackTrace);
    },
  );
}

Logging Messages

You can use the logging functions to send logs to the native side.
Each log function requires a tag and a message, and optionally a LogFlow object.


void main() {
  // Log an error
  LogDrop.logError(
    tag: "LoginScreen",
    message: "Login failed due to invalid credentials",
  );

  // Log a debug message
  LogDrop.logDebug(
    tag: "ApiClient",
    message: "Request sent to /users endpoint",
  );

  // Log an info message
  LogDrop.logInfo(
    tag: "PaymentFlow",
    message: "Payment initialized successfully",
  );

  // Log a warning message
  LogDrop.logWarning(
    tag: "ProfileUpdate",
    message: "Profile picture is too large, compressing...",
  );

  // Using LogFlow
  final flow = LogFlow(
    name: "Checkout",
    id: "flow-123",
    customAttributes: {
      "cartId": "cart-456",
      "userId": "user-789",
    },
  );

  LogDrop.logInfo(
    tag: "CheckoutScreen",
    message: "User started checkout flow",
    logFlow: flow,
  );
}


Push Notifications

⚠️ Before using these functions, make sure you have requested notification permission on the device (both Android and iOS require explicit permission).

These methods should be called inside the push notification callbacks of your app:

import 'package:logdrop_flutter_sdk/logdropsdk.dart';

Future<void> setupPushNotifications() async {
  // 1. Request notification permission from the user
  // (example for FlutterFire Messaging, adapt to your push SDK)
  await FirebaseMessaging.instance.requestPermission();

  // 2. Listen for new push tokens (FCM)
  FirebaseMessaging.instance.onTokenRefresh.listen((token) {
    LogDrop.onNewFcmPushToken(token);
  });

  // 3. Handle incoming push notifications
  FirebaseMessaging.onMessage.listen((RemoteMessage message) {
    LogDrop.onRemoteMessageReceived(message.data);
  });

  // (For Huawei devices, use HMS push SDK and call onNewHmsPushToken)
}

Updating user

void onUserLogin(String userId) {
  // 4. When the user logs in or updates
  LogDrop.userUpdate(userId);
}