Skip to content

Instantly share code, notes, and snippets.

@NITIN-ME

NITIN-ME/main.dart

Created May 29, 2020
Embed
What would you like to do?
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<DataPoint> timeline = List<DataPoint>();
void loadData(){
setState(() {
jsonResponse = jsonResponse['timelineitems'][0];
// print(jsonResponse);
jsonResponse.forEach((key, val){
if(key != 'stat'){
//print(key);
//print(val['total_cases']);
timeline.add(DataPoint(key, val['total_cases']));
}
});
print(timeline.length);
print("\n\n");
//print(timeline);
});
}
@override
void initState() {
super.initState();
CallAPI.getData(loadData);
}
@override
Widget build(BuildContext context) {
if(jsonResponse == null){
return Scaffold(
appBar: AppBar(
title: Center(
child: Text(
'CoronaVirus Tracker',
),
),
backgroundColor: Colors.purple,
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: InkWell(
child: Icon(Icons.show_chart, color: Colors.white,),
onTap: (){},
splashColor: Colors.red,
),
),
],
),
body: Center(child: Text('Loading Data...'),),
);
}
else{
return Scaffold(
appBar: AppBar(
title: Center(
child: Text(
'CoronaVirus Tracker',
),
),
backgroundColor: Colors.purple,
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: InkWell(
child: Icon(Icons.show_chart, color: Colors.white,),
onTap: (){
Navigator.pushNamed(context, '/graph', arguments: timeline);
},
splashColor: Colors.red,
),
),
],
),
body: ShowListView(timeline),
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment