vpn_info 0.0.3 copy "vpn_info: ^0.0.3" to clipboard
vpn_info: ^0.0.3 copied to clipboard

A Flutter package which provides connected vpn information.

vpn_info #

Pub License: BSD 2-Clause "Simplified"

A Flutter package that provides utilities for checking VPN connection status and obtaining details about the connected VPN.

Note: This package is in active development. Feel free to use it, and contributions are welcome.

Table of Contents #

Installation #

Add vpn_info to your pubspec.yaml file:


dependencies:
  vpn_info: ^1.0.0

Run the following command to install the package:

$ flutter pub get

Usage #

Import the package:


import 'package:vpn_info/vpn_info.dart';

Methods #

Future<bool> isVpnConnected() #

Check if the device has an active VPN connection.


bool vpnConnected = await VpnInfo.isVpnConnected();

Future<String?> getConnectedVpnProtocolName() #

Get the name of the connected VPN interface.


String? vpnInterfaceName = await VpnInfo.getConnectedVpnProtocolName();

// Perform a null check later in code

Future<List<InternetAddress>?> getConnectedVpnAddresses() #

Get the IP Address and version of the connected VPN interface as a list of InternetAddress objects.


List<InternetAddress>? vpnInterfaceName = await VpnInfo.getConnectedVpnAddresses();

// Perform a null check later in code

Example #


import 'dart:io';

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("VPN Info"),
      ),
      body: Center(
        child: Column(
          children: [
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                const Text('VPN connected:'),
                const SizedBox(width: 10.0),
                FutureBuilder(
                  future: VpnInfo.isVpnConnected(),
                  builder: (context, AsyncSnapshot<bool> snapshot) {
                    if (snapshot.hasData) {
                      return Text(
                        snapshot.data.toString(),
                        style: Theme.of(context).textTheme.headlineMedium,
                      );
                    } else {
                      return const CircularProgressIndicator();
                    }
                  },
                ),
              ],
            ),
            const SizedBox(height: 20.0),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                const Text('VPN name:'),
                const SizedBox(width: 10.0),
                FutureBuilder(
                  future: VpnInfo.getConnectedVpnProtocolName(),
                  builder: (context, AsyncSnapshot<String?> snapshot) {
                    if (snapshot.hasData) {
                      return Text(
                        snapshot.data.toString(),
                        style: Theme.of(context).textTheme.headlineMedium,
                      );
                    } else {
                      return Text(
                        'No VPN',
                        style: Theme.of(context).textTheme.headlineMedium,
                      );
                    }
                  },
                ),
              ],
            ),
            const SizedBox(height: 20.0),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                const Text('VPN addresses:'),
                const SizedBox(width: 10.0),
                FutureBuilder(
                  future: VpnInfo.getConnectedVpnAddresses(),
                  builder: (context,
                      AsyncSnapshot<List<InternetAddress>?> snapshot) {
                    if (snapshot.hasData) {
                      return Text(
                        snapshot.data.toString(),
                        style: Theme.of(context).textTheme.headlineMedium,
                      );
                    } else {
                      return Text(
                        'No VPN',
                        style: Theme.of(context).textTheme.headlineMedium,
                      );
                    }
                  },
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}


Issues #

Found a bug or have a feature request? Create an issue on the GitHub Issues page.

Contributing #

Contributions are welcome! Fork the repo, make your changes, and submit a pull request.

2
likes
160
points
19
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package which provides connected vpn information.

Repository (GitHub)
View/report issues

License

BSD-2-Clause (license)

Dependencies

flutter

More

Packages that depend on vpn_info