wifi_status 0.1.0 copy "wifi_status: ^0.1.0" to clipboard
wifi_status: ^0.1.0 copied to clipboard

A Flutter package to check Wi-Fi connection status and monitor network changes in real-time with WifiState enums, live streams, and UI widgets.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Wi-Fi Status Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const WifiHomePage(),
    );
  }
}

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

  @override
  State<WifiHomePage> createState() => _WifiHomePageState();
}

class _WifiHomePageState extends State<WifiHomePage> {
  String _manualCheckResult = 'Not checked yet';

  Future<void> _performManualCheck() async {
    final state = await WifiStatus.checkState();
    final legacyString = await WifiStatus.getWifiStatus();
    setState(() {
      _manualCheckResult =
          'State: ${state.name} (${state.label})\nLegacy String: $legacyString';
    });
  }

  @override
  Widget build(BuildContext context) {
    return WifiStatusListener(
      onConnected: () {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(
            content: Text('Connected to Wi-Fi!'),
            backgroundColor: Colors.green,
          ),
        );
      },
      onDisconnected: () {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(
            content: Text('Disconnected from Wi-Fi!'),
            backgroundColor: Colors.red,
          ),
        );
      },
      child: Scaffold(
        appBar: AppBar(
          title: const Text('Wi-Fi Status Example'),
          actions: const [
            Padding(
              padding: EdgeInsets.only(right: 16.0),
              child: WifiStatusIcon(size: 28),
            ),
          ],
        ),
        body: SingleChildScrollView(
          padding: const EdgeInsets.all(24.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              const Text(
                'Live Connection Status Banner:',
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 12),
              const WifiStatusBanner(),
              const SizedBox(height: 24),
              const Text(
                'Dynamic Builder Usage:',
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 12),
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: WifiStatusBuilder(
                    builder: (context, state) {
                      return Row(
                        children: [
                          Icon(
                            state.isWifi
                                ? Icons.wifi
                                : state.isMobile
                                    ? Icons.signal_cellular_4_bar
                                    : Icons.wifi_off,
                            color: state.isConnected
                                ? Colors.green
                                : Colors.red,
                          ),
                          const SizedBox(width: 12),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                'Status: ${state.label}',
                                style: const TextStyle(
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                              Text('Is Wi-Fi: ${state.isWifi}'),
                              Text('Is Mobile Data: ${state.isMobile}'),
                            ],
                          ),
                        ],
                      );
                    },
                  ),
                ),
              ),
              const SizedBox(height: 24),
              const Text(
                'Manual Status Check:',
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 12),
              ElevatedButton.icon(
                onPressed: _performManualCheck,
                icon: const Icon(Icons.refresh),
                label: const Text('Check Wi-Fi Status Now'),
              ),
              const SizedBox(height: 12),
              Text(
                _manualCheckResult,
                style: const TextStyle(fontSize: 14, fontStyle: FontStyle.italic),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
150
points
95
downloads

Documentation

API reference

Publisher

verified publishermahafujerrahman.xyz

Weekly Downloads

A Flutter package to check Wi-Fi connection status and monitor network changes in real-time with WifiState enums, live streams, and UI widgets.

Repository (GitHub)
View/report issues

Topics

#wifi #connectivity #network #wifi-status

License

MIT (license)

Dependencies

connectivity_plus, flutter

More

Packages that depend on wifi_status