Created
December 4, 2019 13:24
-
-
Save sagarshende23/e15b68a19927d1413ca0f93659864abb 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:flutter_offline/flutter_offline.dart'; | |
void main() => runApp(new MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text("Connection"), | |
), | |
body: Builder( | |
builder: (BuildContext context) { | |
return OfflineBuilder( | |
connectivityBuilder: (BuildContext context, | |
ConnectivityResult connectivity, Widget child) { | |
final bool connected = | |
connectivity != ConnectivityResult.none; | |
return Stack( | |
fit: StackFit.expand, | |
children: [ | |
child, | |
Positioned( | |
left: 0.0, | |
right: 0.0, | |
height: 32.0, | |
child: AnimatedContainer( | |
duration: const Duration(milliseconds: 300), | |
color: | |
connected ? Color(0xFF00EE44) : Color(0xFFEE4400), | |
child: connected | |
? Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
"OFFLINE", | |
style: TextStyle(color: Colors.white), | |
), | |
], | |
) | |
: Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
"OFFLINE", | |
style: TextStyle(color: Colors.white), | |
), | |
SizedBox( | |
width: 8.0, | |
), | |
SizedBox( | |
width: 12.0, | |
height: 12.0, | |
child: CircularProgressIndicator( | |
strokeWidth: 2.0, | |
valueColor: | |
AlwaysStoppedAnimation<Color>( | |
Colors.white), | |
), | |
), | |
], | |
), | |
), | |
), | |
], | |
); | |
}, | |
child: Center( | |
child: Text("ONLINE Or OFFLINE"), | |
), | |
); | |
}, | |
)), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment