Created
April 15, 2020 08:07
-
-
Save sokunsamnang/c7f2eb5e4af8148891fd00a6c69990a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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:connectivity_widget/connectivity_widget.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget{ | |
Widget build(context){ | |
ConnectivityUtils.instance.setCallback((response) => response.contains("This is a test!")); | |
ConnectivityUtils.instance.setServerToPing("https://gist.githubusercontent.com/Vanethos/dccc4b4605fc5c5aa4b9153dacc7391c/raw/355ccc0e06d0f84fdbdc83f5b8106065539d9781/gistfile1.txt"); | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Connectivity Widget Demo'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget{ | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State <MyHomePage>{ | |
Widget build (BuildContext context){ | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Connectivity'), | |
), | |
body: Column( | |
children: <Widget>[ | |
_balanceTokens(context), | |
_internetConnection(), | |
], | |
), | |
); | |
} | |
Container _balanceTokens(context){ | |
return Container( | |
margin: EdgeInsets.all(15), | |
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 11), | |
decoration: BoxDecoration( | |
gradient: LinearGradient( | |
colors: [Colors.deepPurple, Colors.blueAccent], | |
begin: Alignment.topLeft, | |
end: Alignment.bottomRight, | |
), | |
border: Border.all(color: Colors.white, width: 0, style: BorderStyle.solid), | |
borderRadius: BorderRadius.all(Radius.circular(25.0)), | |
boxShadow: [ | |
BoxShadow( | |
color: Colors.grey, | |
offset: Offset(0, 3), | |
blurRadius: 6, | |
spreadRadius: 1 | |
), | |
], | |
), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: <Widget>[ | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
SizedBox(width: 20), | |
Text('Current Tokens', | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: 15), | |
), | |
], | |
), | |
], | |
), | |
SizedBox(height: 20), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: <Widget>[ | |
Column( | |
crossAxisAlignment: CrossAxisAlignment.end, | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
Text( | |
'\$', | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: 25 | |
), | |
), | |
SizedBox(width: 13), | |
Text('999,99', | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: 45 | |
), | |
), | |
], | |
), | |
], | |
) | |
], | |
), | |
], | |
), | |
); | |
} | |
Container _internetConnection(){ | |
ConnectivityUtils.instance.setCallback((response) => response.contains("This is a test!")); | |
ConnectivityUtils.instance.setServerToPing("https://gist.githubusercontent.com/Vanethos/dccc4b4605fc5c5aa4b9153dacc7391c/raw/355ccc0e06d0f84fdbdc83f5b8106065539d9781/gistfile1.txt"); | |
return Container( | |
child: ConnectivityWidget( | |
builder: (context, isOnline) => Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
SizedBox(height: 50), | |
Icon(Icons.wifi, size: 70), | |
Text("${isOnline ? 'Online' : 'Offline'}", style: TextStyle(fontSize: 30, color: isOnline ? Colors.green : Colors.red),), | |
SizedBox(height: 10), | |
Text( | |
"${isOnline ? 'Internet Connected' : 'Internet Disconnected'}", | |
), | |
], | |
), | |
), | |
), // This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment