Skip to Content
SDK IntegrationDart / Flutter

Flutter SDK

Integrate TrustPin into your Flutter application for cross-platform certificate pinning on iOS, Android, and macOS.

Platform Requirements

PlatformMinimum Version
iOS13.0+
AndroidAPI 21+ (Recommended: API 25+)
macOS13.0+

Additional Requirements:

  • iOS/macOS: Swift 5.5+
  • Android: Kotlin 2.3.0+

Installation

Add TrustPin to your pubspec.yaml:

dependencies: trustpin_sdk: ^4.0.0

Then install:

flutter pub get

Quick Start

1. Get Your Credentials

Sign in to the TrustPin Dashboard  and retrieve:

  • Organization ID
  • Project ID
  • Public Key (Base64-encoded)

2. Initialize TrustPin

Add initialization to your app’s main entry point:

import 'package:flutter/material.dart'; import 'package:trustpin_sdk/trustpin_sdk.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); // Initialize TrustPin try { await TrustPin.setLogLevel(TrustPinLogLevel.debug); await TrustPin.setup( organizationId: 'your-org-id', projectId: 'your-project-id', publicKey: 'your-base64-public-key', mode: TrustPinMode.strict, ); print('TrustPin initialized successfully'); } catch (e) { print('TrustPin initialization failed: $e'); } runApp(MyApp()); }

Integration Approaches

TrustPin offers multiple integration methods:

ApproachBest ForSetup Complexity
Dio HTTP Client (Recommended)Most Flutter apps🟢 Minimal
Standard HTTP ClientApps using http package🟢 Minimal
Direct Certificate VerificationCustom implementations🟠 Advanced

The SDK provides a built-in TrustPinDioInterceptor:

import 'package:dio/dio.dart'; import 'package:trustpin_sdk/trustpin_sdk.dart'; // Create Dio with TrustPin certificate validation final dio = Dio(); dio.interceptors.add(TrustPinDioInterceptor()); // All HTTPS requests now have certificate pinning try { final response = await dio.get('https://api.example.com/data'); print('Request successful: ${response.statusCode}'); } on DioException catch (e) { if (e.error is TrustPinException) { final trustPinError = e.error as TrustPinException; print('Pinning failed: ${trustPinError.code}'); } }

Best Practices

Setup & Initialization

  1. Call WidgetsFlutterBinding.ensureInitialized() before TrustPin setup
  2. Initialize in main() before running the app
  3. Handle setup errors gracefully - don’t block app launch
  4. Set log level before setup for complete logging

Security

  1. Use TrustPinMode.strict in production
  2. Monitor pin validation failures
  3. Use SPKI or rotate pins before expiration
  4. Keep credentials secure (use environment variables)
  5. Use HTTPS for all pinned domains

Performance

  1. Configuration caching is automatic (10-minute TTL)
  2. Reuse HTTP client instances
  3. Use minimal log levels in production
  4. Initialize early in app lifecycle

Complete Documentation

For detailed information on all integration approaches (http package, direct verification), error handling types, environment configuration, macOS sandbox setup, and production deployment, visit the complete documentation:

TrustPin Flutter Documentation 


Resources