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

A smart network awareness widget that handles offline states, internet connectivity checks, and automatic UI switching.

ConnectGuard 🌐 #

A lightweight, robust Flutter widget that simplifies handling offline/online network states.

Unlike standard connectivity checks which only verify if Wi-Fi is connected, ConnectGuard verifies actual internet access by pinging a server, ensuring your users never see a "Connected" state when the router has no internet.

Features #

  • Real Internet Check: Verifies actual data connection, not just Wi-Fi status.
  • Reactive Widget: ConnectGuard automatically switches between your app content and an offline widget.
  • Zero Boilerplate: No need to manage Streams or initState manually.
  • Callback Support: Trigger Snackbars or alerts easily when the connection status changes.
  • Customizable: Provide your own "Offline" and "Loading" widgets.

Getting Started #

Add the package to your pubspec.yaml:

dependencies:
  connect_guard: ^0.0.1

Usage #

Simply wrap your screen (or specific widget) with ConnectGuard:

import 'package:connect_guard/connect_guard.dart';

ConnectGuard(
  // 1. The UI to show when Online
  builder: (context) {
    return Center(child: Text("You are Online!"));
  },

  // 2. The UI to show when Offline (Optional)
  offlineBuilder: (context) {
    return Center(child: Text("No Internet Connection"));
  },

  // 3. Callback for side effects (Optional)
  onConnectivityChanged: (isOnline) {
    if (!isOnline) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text("Connection lost!")),
      );
    }
  },
);
2
likes
160
points
126
downloads

Publisher

unverified uploader

Weekly Downloads

A smart network awareness widget that handles offline states, internet connectivity checks, and automatic UI switching.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

connectivity_plus, flutter, internet_connection_checker_plus, rxdart

More

Packages that depend on connect_guard