internet_status 1.0.0
internet_status: ^1.0.0 copied to clipboard
Checks whether the device really has internet access (DNS, socket and HTTP), streams the status, and shows an animated offline banner.
import 'package:flutter/material.dart';
import 'package:internet_status/internet_status.dart';
void main() => runApp(const MaterialApp(home: StatusPage()));
/// Shows whether the device really has internet access, and why not when it
/// does not.
class StatusPage extends StatelessWidget {
const StatusPage({super.key});
@override
Widget build(BuildContext context) {
final checker = InternetConnectionChecker();
return Scaffold(
appBar: AppBar(title: const Text('internet_status')),
body: Center(
child: StreamBuilder<InternetResult>(
stream: checker.onInternetConnectivityChanged,
builder: (context, snapshot) {
final result = snapshot.data;
if (result == null) return const CircularProgressIndicator();
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(result.hasInternetAccess ? Icons.wifi : Icons.wifi_off, size: 48),
Text(
result.hasInternetAccess
? 'Online (${result.connectionType?.name ?? 'unknown'})'
: 'Offline: ${result.failureReason ?? 'a check failed'}',
),
],
);
},
),
),
);
}
}