Last active
June 13, 2021 10:52
-
-
Save sigmapie8/d71f0f9f19dbfcfb8426b69d37230843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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