internet_connection_checker_plus 2.0.0 internet_connection_checker_plus: ^2.0.0 copied to clipboard
A Flutter package to check your internet connection with subsecond response times, even on mobile networks!
// Dart Packages
import 'dart:async';
// Flutter Packages
import 'package:flutter/material.dart';
// This Package
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Internet Connection Checker Plus Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Internet Connection Checker Plus Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
InternetStatus? _connectionStatus;
late StreamSubscription<InternetStatus> _subscription;
@override
void initState() {
super.initState();
_subscription = InternetConnection().onStatusChange.listen((status) {
setState(() {
_connectionStatus = status;
});
});
}
@override
void dispose() {
_subscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Your internet connection status is:',
),
Text(
_connectionStatus?.toString() ?? 'Unknown',
style: Theme.of(context).textTheme.titleLarge,
),
],
),
),
);
}
}