global_internet_listener 0.0.1
global_internet_listener: ^0.0.1 copied to clipboard
global_internet_listener is a lightweight Flutter package that enables global internet connectivity monitoring across your entire app with just a few lines of code.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:global_internet_listener/global_internet_listener.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Internet Connectivity Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
// ✅ Enable global internet checker
builder: (context, child) {
return GlobalInternetListener(
child: child ?? const SizedBox.shrink(),
);
},
home: const MyHomePage(title: 'Home Page'),
);
}
}
// 🔹 HOME PAGE
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() => setState(() => _counter++);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pushed the button this many times:'),
Text('$_counter', style: Theme.of(context).textTheme.headlineMedium),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (_) => const SecondPage()));
},
child: const Text("Go to Second Page"),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
// 🔹 SECOND PAGE
class SecondPage extends StatelessWidget {
const SecondPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Second Page")),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (_) => const ThirdPage()));
},
child: const Text("Go to Third Page"),
),
),
);
}
}
// 🔹 THIRD PAGE
class ThirdPage extends StatelessWidget {
const ThirdPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Third Page")),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (_) => const FourthPage()));
},
child: const Text("Go to Fourth Page"),
),
),
);
}
}
// 🔹 FOURTH PAGE
class FourthPage extends StatelessWidget {
const FourthPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Fourth Page")),
body: const Center(
child: Text("You're on the Fourth Page"),
),
);
}
}