⚡ TL;DR
You have to use the 'Connectivity Flutter Package' to achieve this feature on your App. This package helps to know whether your device is online or offline.
To implement an automatic internet connectivity message in your Flutter app, you’ll use the connectivity_plus package. This package allows you to determine the device’s connectivity status and react accordingly. Follow the steps below to add this functionality to your app.
To show an offline message in Flutter, listen to Connectivity().onConnectivityChanged from the connectivity_plus package and display a banner when the result is ConnectivityResult.none. Keep in mind that connectivity_plus only detects the network interface — a device can report Wi-Fi while the actual internet is down — so for a true online/offline check, pair it with the internet_connection_checker package. Also remember the Android INTERNET permission in your manifest.
Important caveat: connectivityplus tells you whether the device has a _network interface (Wi-Fi, Ethernet, or mobile data), not whether that interface can actually reach the internet. A Wi-Fi network behind a captive portal, or one with its router unplugged, still reports
ConnectivityResult.wifi. Use connectivity_plus for fast, free interface changes, and combine it with internet_connection_checker (which pings real hosts) when you need to know if the internet is genuinely reachable. I show both below.
Step 1: Add connectivity_plus to Your pubspec.yaml
First, include the connectivity_plus package in your pubspec.yaml file (plus internet_connection_checker if you want the real reachability check):
dependencies:
flutter:
sdk: flutter
connectivity_plus: ^6.1.4
internet_connection_checker: ^1.0.0+1On Android, also add the internet permission to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />Step 2: Implement the Connectivity Checker
Below is a complete example of how to create a widget that monitors connectivity status and displays an offline message when there is no internet connection.
import 'dart:async';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
class CheckConnection extends StatefulWidget {
_CheckConnectionState createState() => _CheckConnectionState();
}
class _CheckConnectionState extends State<CheckConnection> {
StreamSubscription? internetConnection;
bool isOffline = false;
//set variable for Connectivity subscription listener
void initState() {
internetConnection =
Connectivity().onConnectivityChanged.listen((connectivityResult) {
if (connectivityResult.contains(ConnectivityResult.none)) {
//there is no any connection
setState(() {
isOffline = true;
});
} else if (connectivityResult.contains(ConnectivityResult.mobile) ||
connectivityResult.contains(ConnectivityResult.wifi)) {
//connection is from Wifi or Mobile
setState(() {
isOffline = false;
});
}
});
super.initState();
}
void dispose() {
internetConnection?.cancel();
//cancel internet connection subscription after you are done
super.dispose();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
"Check Connection",
),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
child: errorMessage(
"No Internet Connection Available",
isOffline,
),
//to show internet connection message on isOffline = true.
),
Container(
margin: const EdgeInsets.all(
30,
),
width: double.infinity,
child: const Center(
child: Text(
"Check Connections",
style: TextStyle(
fontSize: 20,
),
),
),
),
],
),
),
);
}
Widget errorMessage(
String text,
bool show,
) {
//error message widget.
if (show == true) {
//if error is true then show error message box
return Container(
padding: const EdgeInsets.all(
10.00,
),
margin: const EdgeInsets.only(
bottom: 10.00,
),
color: Colors.red,
child: Row(children: [
Container(
margin: const EdgeInsets.only(
right: 6.00,
),
child: const Icon(
Icons.info,
color: Colors.white,
),
), // icon for error message
Text(
text,
style: const TextStyle(
color: Colors.white,
),
),
//show error message text
]),
);
} else {
//if error is false, return empty container.
return Container();
}
}
}Note how the errorMessage widget works in the Column above: because isOffline is false at startup, errorMessage returns an empty Container that collapses to zero size. The moment the listener fires with ConnectivityResult.none, setState flips isOffline to true and the same slot re-renders as the red banner. That’s why the banner appears in place at the top of the column rather than pushing your content around unpredictably — keep it as the first child of the Column if you want the message always at the top, and the layout shift stays predictable.
A Full-App Offline Banner with MaterialBanner
Instead of reserving a slot in one screen, you can wrap your entire app in a builder that shows a banner above every page. This pattern listens to connectivity in a small widget and uses a MaterialBanner so the message overlays whatever screen the user is on:
import 'dart:async';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
void main() => runApp(const OfflineBannerApp());
class OfflineBannerApp extends StatefulWidget {
const OfflineBannerApp({super.key});
State<OfflineBannerApp> createState() => _OfflineBannerAppState();
}
class _OfflineBannerAppState extends State<OfflineBannerApp> {
late final StreamSubscription<List<ConnectivityResult>> _subscription;
bool _isOffline = false;
void initState() {
super.initState();
_subscription = Connectivity().onConnectivityChanged.listen((results) {
final offline = results.contains(ConnectivityResult.none);
if (offline != _isOffline) {
setState(() => _isOffline = offline);
}
});
}
void dispose() {
_subscription.cancel();
super.dispose();
}
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) {
if (_isOffline) {
WidgetsBinding.instance.addPostFrameCallback((_) {
ScaffoldMessenger.of(context).showMaterialBanner(
MaterialBanner(
backgroundColor: Colors.red,
content: const Text(
'No Internet Connection Available',
style: TextStyle(color: Colors.white),
),
actions: [
TextButton(
onPressed: () =>
ScaffoldMessenger.of(context).hideCurrentMaterialBanner(),
child: const Text('Dismiss'),
),
],
),
);
});
} else {
ScaffoldMessenger.of(context).hideCurrentMaterialBanner();
}
return const Center(child: Text('Your app content goes here'));
},
),
),
);
}
}The addPostFrameCallback matters: showMaterialBanner can’t be called during the build phase, so we schedule it for right after the frame renders. For the stricter “real internet” check, replace the connectivity listener’s body with await InternetConnectionChecker().hasConnection; (from internet_connection_checker) and use that boolean instead — or debounce it behind the connectivity stream so you only ping when an interface actually goes up or down.
Conclusion
By following the above steps, you can seamlessly integrate an internet connectivity checker into your Flutter app. The connectivity_plus package helps you listen for connectivity changes and update the UI accordingly to inform the user when the device is offline. This enhances the user experience by providing immediate feedback on the network status.
Related Posts
- Enhancing File Manipulation in Flutter: Best Practices and Examples
- Flutter Debug Banner Removal: Best Practices and Techniques
- A Comprehensive Guide to Flutter Buttons: Choosing the Right One for Your App
- How to Change minSdkVersion in Flutter: 2 Simple Approaches
References
- pub.dev: connectivity_plus
- pub.dev: internet_connection_checker
- MaterialBanner class — Flutter API docs
- StreamSubscription class — Dart API docs
- Android INTERNET permission — Android developer docs
FAQ
How do I show an offline message in Flutter?
Add the connectivity_plus package, listen to its onConnectivityChanged stream, and when the results contain ConnectivityResult.none, set a state flag that renders a red banner or MaterialBanner saying no internet connection is available. Remember to cancel the stream subscription in dispose, and add the Android INTERNET permission to your manifest so checks work on Android devices.
Does connectivity_plus actually tell you if the internet is working in Flutter?
No — connectivity_plus only reports the network interface, such as Wi-Fi or mobile data, not real reachability. A router with no internet or a captive portal still reports wifi. For a genuine online check, pair it with the internet_connection_checker package, which pings real hosts and returns a boolean you can drive your offline banner from.
What permission is needed to check internet connectivity in a Flutter Android app?
The Android INTERNET permission must be declared in android/app/src/main/AndroidManifest.xml with a uses-permission tag. Without it, connectivity checks and any network requests fail on Android even though the same code works on iOS or desktop. It is a normal-level permission, so no runtime permission dialog is required from the user.
How can I show an offline banner across every screen in Flutter?
Wrap your app in a builder that listens to connectivity changes and uses ScaffoldMessenger’s showMaterialBanner, which overlays the banner above whatever screen is visible. Call showMaterialBanner inside addPostFrameCallback because it cannot run during the build phase, and call hideCurrentMaterialBanner when connectivity returns so the banner dismisses itself automatically.

Written by Mihir Pipermitwala
Senior Full Stack Consultant & Mobile Engineering Specialist building user-focused applications in healthcare with Flutter, Dart and React Native. I write about what I actually build and test — every tutorial here comes from real project work.
More about Mihir →