Skip to content

Instantly share code, notes, and snippets.

@sigmapie8
Last active June 13, 2021 10:52
Show Gist options
  • Save sigmapie8/d71f0f9f19dbfcfb8426b69d37230843 to your computer and use it in GitHub Desktop.
Save sigmapie8/d71f0f9f19dbfcfb8426b69d37230843 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';
class CheckConnection extends StatefulWidget {
@override
_CheckConnectionState createState() => _CheckConnectionState();
}
class _CheckConnectionState extends State<CheckConnection> {
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: InternetConnectionChecker().hasConnection,
builder: (BuildContext context, AsyncSnapshot<bool> connected) {
if (!connected.hasData) {
return ListTile(
leading: Icon(
Icons.circle,
color: Colors.grey,
),
title: CircularProgressIndicator(),
);
} else {
return ListTile(
leading: Icon(
Icons.circle,
color: (connected.data!) ? Colors.green : Colors.red,
),
title:
(connected.data!) ? Text('Connected') : Text('Not Connected'),
);
}
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment