-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
280 additions
and
51 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:covid19updates/services/networking.dart'; | ||
|
||
class GlobalInfo { | ||
double gActive; | ||
double gConfirmed; | ||
double gDeaths; | ||
double gRecovered; | ||
List countriesData; | ||
|
||
Future getGlobalInfo() async { | ||
var data = await NetworkHelper().getGlobalData(); | ||
updateData(data); | ||
} | ||
|
||
void updateData(data) { | ||
this.gConfirmed = | ||
double.tryParse((data['Global']['TotalConfirmed']).toString()); | ||
gDeaths = double.tryParse((data['Global']['TotalDeaths']).toString()); | ||
gRecovered = double.tryParse((data['Global']['TotalRecovered']).toString()); | ||
gActive = gConfirmed - gRecovered - gDeaths; | ||
countriesData = data['Countries']; | ||
} | ||
} | ||
//Countries |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:covid19updates/data/global_info.dart'; | ||
import 'package:covid19updates/screens/global_screen.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:connectivity/connectivity.dart'; | ||
import 'package:provider/provider.dart'; | ||
import '../screens/show_msg.dart'; | ||
|
||
class GlobalPage extends StatefulWidget { | ||
@override | ||
_GlobalPageState createState() => _GlobalPageState(); | ||
} | ||
|
||
class _GlobalPageState extends State<GlobalPage> { | ||
Future _start; | ||
bool isConnected; | ||
GlobalInfo _info = GlobalInfo(); | ||
_getData() async { | ||
return await _info.getGlobalInfo(); | ||
} | ||
|
||
Future<Null> checkConnection() async { | ||
var connection = await Connectivity().checkConnectivity(); | ||
if (connection == ConnectivityResult.mobile || | ||
connection == ConnectivityResult.wifi) { | ||
isConnected = true; | ||
} else { | ||
isConnected = false; | ||
} | ||
} | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_start = _getData(); | ||
checkConnection(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Provider( | ||
create: (context) => _info, | ||
child: Scaffold( | ||
backgroundColor: Color(0xff1b1b2f), | ||
body: FutureBuilder( | ||
future: _start, | ||
builder: (context, snapshot) { | ||
switch (snapshot.connectionState) { | ||
case ConnectionState.active: | ||
case ConnectionState.waiting: | ||
return ShowLoading(); | ||
case ConnectionState.done: | ||
return isConnected ? GlobalScreen() : ShowConnectionError(); | ||
case ConnectionState.none: | ||
default: | ||
return ShowError(); | ||
} | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:covid19updates/data/global_info.dart'; | ||
import 'package:covid19updates/widgets/coutries_stream.dart'; | ||
import 'package:covid19updates/widgets/curved_top.dart'; | ||
import 'package:covid19updates/widgets/data_cards.dart'; | ||
import 'package:covid19updates/widgets/top_title.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class GlobalScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
final GlobalInfo _info = Provider.of<GlobalInfo>(context); | ||
return CustomScrollView( | ||
slivers: <Widget>[ | ||
SliverAppBar( | ||
elevation: 0.0, | ||
floating: true, | ||
expandedHeight: 100, | ||
title: Text('Covid-19 Updates', | ||
style: TextStyle(fontSize: 20, color: Colors.white)), | ||
flexibleSpace: FlexibleSpaceBar( | ||
background: Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: <Widget>[ | ||
TopTitle( | ||
title: 'Global', | ||
), | ||
], | ||
), | ||
), | ||
), | ||
CurvedTop(), | ||
SliverToBoxAdapter( | ||
child: DataCards( | ||
confirmed: _info.gConfirmed, | ||
active: _info.gActive, | ||
recovered: _info.gRecovered, | ||
deaths: _info.gDeaths, | ||
), | ||
), | ||
CountriesStream(), | ||
], | ||
); | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:covid19updates/widgets/list_tile_data.dart'; | ||
import 'package:covid19updates/data/global_info.dart'; | ||
|
||
class CountriesStream extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
final GlobalInfo _info = Provider.of<GlobalInfo>(context); | ||
return SliverList( | ||
delegate: SliverChildBuilderDelegate( | ||
(_, index) { | ||
final oneCountry = _info.countriesData[index]; | ||
var country = oneCountry['Country']; | ||
var confirmed = | ||
double.tryParse((oneCountry['TotalConfirmed']).toString()); | ||
var deaths = double.tryParse((oneCountry['TotalDeaths']).toString()); | ||
var recovered = | ||
double.tryParse((oneCountry['TotalRecovered']).toString()); | ||
return ListTileData( | ||
name: country, | ||
active: confirmed - deaths - recovered, | ||
confirmed: confirmed, | ||
deaths: deaths, | ||
recovered: recovered, | ||
); | ||
}, | ||
childCount: _info.countriesData.length, | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.