Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PlayerProfileState extends State<PlayerProfile> {
- String name, playingRole, battingStyle, country, imageURL;
- int pid, player_id;
- String half_test,
- century_test,
- avg_test,
- matches_test,
- runs_test,
- highest_test;
- String half_odi, century_odi, avg_odi, matches_odi, runs_odi, highest_odi;
- String half_t, century_t, avg_t, matches_t, runs_t, highest_t;
- bool isData = false;
- Map data = new Map();
- var playerIds = [{"pid":35320},{"pid":28114},{"pid":28779},{"pid":28763},{"pid":30176},{"pid":7133},{"pid":5390},{"pid":6565},{"pid":8166},{"pid":52337},{"pid":870007},{"pid":52334},{"pid":42606},{"pid":42639},{"pid":46774},{"pid":4021},{"pid":45789},{"pid":11728},{"pid":20387}];
- FetchJson(int ids) async {
- var response = await http.get(
- 'https://cricapi.com/api/playerStats?apikey=apikey&pid=$ids');
- if (response.statusCode == 200) {
- String responseBody = response.body;
- var responseJson = jsonDecode(responseBody);
- pid = responseJson['pid'];
- name = responseJson['name'];
- playingRole = responseJson['playingRole'];
- battingStyle = responseJson['battingStyle'];
- country = responseJson['country'];
- imageURL = responseJson['imageURL'];
- data = responseJson;
- var stats = data['data']['batting'];
- var testStats = stats['tests'];
- var odiStats = stats['ODIs'];
- var tStats = stats['T20Is'];
- // T20 Stats
- matches_t = tStats['Mat'];
- runs_t = tStats['Runs'];
- half_t = tStats['50'];
- century_t = tStats['100'];
- highest_t = tStats['HS'];
- avg_t = tStats['Ave'];
- isData = true;
- setState(() {
- print('UI updated');
- });
- } else {
- print('something went wrong');
- }
- }
- @override
- void initState() {
- var intIds = playerIds.map<int>((m) => m['pid'] as int).toList();
- for (int i = 0; i < intIds.length; i++) {
- FetchJson(intIds[i]);
- }
- }
- @override
- Widget build(BuildContext context) {
- return Container(
- height: 700.0,
- child: ListView.builder(
- shrinkWrap: true,
- itemBuilder: (context, index) {
- return Card(
- child: Container(
- padding: EdgeInsets.all(8.0),
- height: MediaQuery.of(context).size.height - 84,
- width: MediaQuery.of(context).size.width,
- color: Colors.white30,
- child: Stack(
- children: <Widget>[profileDetails(), playerImage()],
- ),
- ),
- );
- },
- ),
- );
- }
Add Comment
Please, Sign In to add comment