Skip to content

Instantly share code, notes, and snippets.

@NITIN-ME
Created May 29, 2020 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NITIN-ME/a647b3700d92524ddb781f8d6430431f to your computer and use it in GitHub Desktop.
Save NITIN-ME/a647b3700d92524ddb781f8d6430431f to your computer and use it in GitHub Desktop.
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