Created
May 29, 2020 08:05
-
-
Save NITIN-ME/a647b3700d92524ddb781f8d6430431f 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
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