flutter_vpn 0.7.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

Flutter VPN plugin #

Pub Package Awesome Flutter

This plugin help developers to access VPN service in their flutter app.
本插件帮助开发者在自己的应用内调用 VPN 服务。

The Android part was implemented by strongswan which support ikev2 protocol.
The iOS part was implemented by NEVPNManager.

Issues and PRs are welcome!

Installation #

For Android #

Modify your app/build.gradle to use abiFilter because flutter doesn't apply abiFilter for target platform yet.

android {
    ...
    buildTypes {
        ...
        release {
            ...
            ndk {
                    if (project.hasProperty('target-platform')) {
                        if (project.property('target-platform') == 'android-arm,android-arm64')
                            abiFilters 'armeabi-v7a', 'arm64-v8a'
                        else if (project.property('target-platform') == 'android-arm')
                            abiFilters 'armeabi-v7a'
                        else if (project.property('target-platform') == 'android-arm64')
                            abiFilters 'arm64-v8a'
                    }
                }
            }
    }
}

The plugin will automatically download pre-build native libraries from here if they haven't been downloaded.

For iOS #

You need to open Personal VPN and Network Extensions capabilities in Xcode: see Project->Capabilities.

VPN connection errors are handled in swift code, you need to use Xcode to see connection errors if there is any.

0.7.0 #

  • Add MTU for Android.
  • Fix service unbinding. (#27)

0.6.0 #

  • Update to StrongSwan 5.8.1.
  • Use original notification from StrongSwan frontend.
  • Automatically retry when a error occured.

BreakingChange

  • In order to compatible with original VpnStateService, CharonVpnState has been changed to CharonErrorState that shows detail kind of error when a generic error is received.

0.5.0 #

  • Fix (#15) event handler for android (Flutter 1.6+).

0.4.0 #

  • Fix state error if disconnect while connecting.
  • Add iOS state handler.

0.3.0 #

  • Add getVpnState for iOS.

0.2.0 #

  • Add getVpnState and getCharonState for Android.

Breaking Change

  • Old FlutterVpnState has been renamed to CharonVpnState which is for Android only. New FlutterVpnState is designed for both Android and iOS platform.

0.1.0 #

  • Support arm64-v8a for android. Please follow README to configure abiFilter for NDK.

Breaking Change

  • Migrate to AndroidX

Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library. Follow Official documents to migrate.

0.0.4 #

  • Add iOS support without status broadcast.

0.0.3 #

  • Add onStateChanged to receive state changes from charon.

0.0.2 (Deprecated) #

  • Implemented simplest IkeV2-eap VPN service.
  • Automatically download native libs before building.

example/lib/main.dart

/**
 * Copyright (C) 2018 Jason C.H
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

import 'package:flutter/material.dart';
import 'package:flutter_vpn/flutter_vpn.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _addressController = TextEditingController();
  final _usernameController = TextEditingController();
  final _passwordController = TextEditingController();

  var state = FlutterVpnState.disconnected;
  var charonState = CharonErrorState.NO_ERROR;

  @override
  void initState() {
    FlutterVpn.prepare();
    FlutterVpn.onStateChanged.listen((s) => setState(() => state = s));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter VPN'),
        ),
        body: ListView(
          padding: const EdgeInsets.all(15.0),
          children: <Widget>[
            Text('Current State: $state'),
            Text('Current Charon State: $charonState'),
            TextFormField(
              controller: _addressController,
              decoration: InputDecoration(icon: Icon(Icons.map)),
            ),
            TextFormField(
              controller: _usernameController,
              decoration: InputDecoration(icon: Icon(Icons.person_outline)),
            ),
            TextFormField(
              controller: _passwordController,
              obscureText: true,
              decoration: InputDecoration(icon: Icon(Icons.lock_outline)),
            ),
            RaisedButton(
              child: Text('Connect'),
              onPressed: () => FlutterVpn.simpleConnect(
                _addressController.text,
                _usernameController.text,
                _passwordController.text,
              ),
            ),
            RaisedButton(
              child: Text('Disconnect'),
              onPressed: () => FlutterVpn.disconnect(),
            ),
            RaisedButton(
                child: Text('Update State'),
                onPressed: () async {
                  var newState = await FlutterVpn.currentState;
                  setState(() => state = newState);
                }),
            RaisedButton(
                child: Text('Update Charon State'),
                onPressed: () async {
                  var newState = await FlutterVpn.charonErrorState;
                  setState(() => charonState = newState);
                }),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_vpn: ^0.7.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_vpn/flutter_vpn.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
79
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test