vpn_connection_detector 1.0.9 copy "vpn_connection_detector: ^1.0.9" to clipboard
vpn_connection_detector: ^1.0.9 copied to clipboard

VPN connection detecting in Dart. Singleton class with state stream & connection check.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final stream = VpnConnectionDetector();

  @override
  void dispose() {
    stream.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Vpn Connection Monitor"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'VPN is active(Stream):',
            ),
            StreamBuilder<VpnConnectionState>(
                stream: stream.vpnConnectionStream,
                builder: (context, AsyncSnapshot<VpnConnectionState> snapshot) {
                  if (snapshot.hasData) {
                    return Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Text(
                        snapshot.data.toString(),
                        textAlign: TextAlign.center,
                        style: Theme.of(context)
                            .textTheme
                            .headlineMedium
                            ?.copyWith(
                              fontSize: 20,
                            ),
                      ),
                    );
                  } else {
                    return const CircularProgressIndicator();
                  }
                }),
            const Divider(),
            const Text(
              'VPN is active(Static):',
            ),
            FutureBuilder<bool>(
                future: VpnConnectionDetector.isVpnActive(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    return Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Text(
                        snapshot.data.toString(),
                        textAlign: TextAlign.center,
                        style: Theme.of(context)
                            .textTheme
                            .headlineMedium
                            ?.copyWith(
                              fontSize: 20,
                            ),
                      ),
                    );
                  } else {
                    return const CircularProgressIndicator();
                  }
                }),
          ],
        ),
      ),
    );
  }
}
27
likes
160
pub points
91%
popularity

Publisher

unverified uploader

VPN connection detecting in Dart. Singleton class with state stream & connection check.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

connectivity_plus, flutter

More

Packages that depend on vpn_connection_detector