ikev2 0.0.1 copy "ikev2: ^0.0.1" to clipboard
ikev2: ^0.0.1 copied to clipboard

PlatformAndroid

Flutter plugin for IKEv2 VPN protocol support.

ikev2 #

Pub License: MIT

A powerful Flutter plugin to setup and control IKEv2 VPN connections using the strongSwan protocol.

ikev2 provides a robust API to manage VPN connections with full support for IKEv2 EAP and PSK authentication methods on Android.

Developed by Orban InfoTech.

Key Features #

  • 🚀 Android Support: Native implementation using strongSwan for high performance.
  • 🍎 iOS Support: Available as a premium add-on (NetworkExtension).
  • 📊 Traffic Statistics: Real-time download/upload speed and total data usage monitoring.
  • 🔐 Secure Authentication: Supports both IKEv2 EAP and PSK methods.
  • 🔔 Notification Support: Integrated native foreground service with status notifications.
  • Connectivity: Automatic handling of network state changes.

🍎 iOS Support (Premium) #

This package on pub.dev provides full Android support.

iOS support (using NetworkExtension) is available as a commercial add-on. If you require the iOS implementation or the complete cross-platform source code, please contact me directly:

👉 Contact via Telegram: Click Here to Buy

Installation #

Android #

Modify your android/app/build.gradle to use abiFilters. This ensures that the correct native libraries are included for each architecture, as Flutter doesn't fully handle this for native .so files automatically yet.

android {
    ...
    buildTypes {
        ...
        release {
            ...
            ndk {
                if (!project.hasProperty('target-platform')) {
                    abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64'
                } else {
                    def platforms = project.property('target-platform').split(',')
                    def platformMap = [
                            'android-arm'  : 'armeabi-v7a',
                            'android-arm64': 'arm64-v8a',
                            'android-x86'  : 'x86',
                            'android-x64'  : 'x86_64',
                    ]
                    abiFilters = platforms.stream().map({ e ->
                        platformMap.containsKey(e) ? platformMap[e] : e
                    }).toArray()
                }
            }
        }
    }
}

The plugin will automatically download pre-built native libraries from GitHub if they haven't been downloaded during the build process.

Usage #

1. Initialize & Prepare #

Before starting a connection, especially on Android, you must prepare the VPN service. This triggers the system's VPN permission dialog if not already granted.

import 'package:ikev2/ikev2.dart';

void initVpn() async {
  // Check if VPN permission is granted
  bool prepared = await IkeV2.prepared;

  if (!prepared) {
    // Request VPN permission
    prepared = await IkeV2.prepare();
  }
}

2. Connect #

You can establish a connection using either EAP (Username/Password) or PSK (Pre-Shared Key).

Connect with IKEv2 EAP

void connect() async {
  await IkeV2.connectIkev2EAP(
    server: "vpn.example.com",
    username: "your-username",
    password: "your-password",
    name: "Orban VPN", // Visible Name in Notification
    // Optional
    remoteId: "optional-remote-id",
    localId: "optional-local-id",
    mtu: 1400,
    port: 500, // Default is usually 500 or 4500
    disableCertValidation: false, // Set to true for self-signed certs (dev only)
  );
}

Connect with IKEv2 PSK

void connectPsk() async {
  await IkeV2.connectIkev2Psk(
    server: "vpn.example.com",
    username: "your-username", // Used as identity if required
    password: "your-pre-shared-key", // PSK
    remoteId: "vpn.example.com",
    localId: "client-id",
    name: "Orban VPN",
  );
}

3. Disconnect #

Stop the VPN service and disconnect.

void disconnect() async {
  await IkeV2.disconnect();
}

4. Listen to Status & Traffic #

Monitor connection state and real-time traffic statistics.

Connection Status:

IkeV2.onStateChanged.listen((state) {
  print("VPN Status Changed: $state");
  // States: connecting, connected, disconnecting, disconnected, error, etc.
});

Traffic Statistics:

To receive traffic updates, start the traffic monitor (usually after connection).

// Start monitoring
IkeV2.startTrafficMonitor();

IkeV2.onTrafficChanged.listen((stats) {
  print("Download Speed: ${stats.downloadSpeed} B/s");
  print("Upload Speed: ${stats.uploadSpeed} B/s");
  print("Total Download: ${stats.totalDownload} bytes");
  print("Total Upload: ${stats.totalUpload} bytes");
  print("Duration: ${stats.duration} seconds");
});

VPN Stages #

Stage Description
connecting The VPN is attempting to establish a connection.
connected The tunnel is successfully established and data can flow.
disconnecting The VPN is in the process of closing.
disconnected The VPN interface is completely stopped.
error An error occurred during the connection attempt.
genericError A generic error state.

Supported Platforms #

Platform Version Notes
Android SDK 21+ Native strongSwan implementation
iOS iOS 15+ Premium Only (Contact for access)
1
likes
140
points
111
downloads

Publisher

verified publisherorbaninfotech.com

Weekly Downloads

Flutter plugin for IKEv2 VPN protocol support.

Homepage

Documentation

API reference

License

LGPL-3.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on ikev2

Packages that implement ikev2