Guest User

Untitled

a guest
Dec 28th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. class PlayerProfileState extends State<PlayerProfile> {
  2. String name, playingRole, battingStyle, country, imageURL;
  3. int pid, player_id;
  4. String half_test,
  5. century_test,
  6. avg_test,
  7. matches_test,
  8. runs_test,
  9. highest_test;
  10. String half_odi, century_odi, avg_odi, matches_odi, runs_odi, highest_odi;
  11. String half_t, century_t, avg_t, matches_t, runs_t, highest_t;
  12. bool isData = false;
  13. Map data = new Map();
  14.  
  15. 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}];
  16.  
  17.  
  18. FetchJson(int ids) async {
  19. var response = await http.get(
  20. 'https://cricapi.com/api/playerStats?apikey=apikey&pid=$ids');
  21.  
  22. if (response.statusCode == 200) {
  23. String responseBody = response.body;
  24. var responseJson = jsonDecode(responseBody);
  25. pid = responseJson['pid'];
  26. name = responseJson['name'];
  27. playingRole = responseJson['playingRole'];
  28. battingStyle = responseJson['battingStyle'];
  29. country = responseJson['country'];
  30. imageURL = responseJson['imageURL'];
  31. data = responseJson;
  32.  
  33. var stats = data['data']['batting'];
  34. var testStats = stats['tests'];
  35. var odiStats = stats['ODIs'];
  36. var tStats = stats['T20Is'];
  37.  
  38. // T20 Stats
  39.  
  40. matches_t = tStats['Mat'];
  41. runs_t = tStats['Runs'];
  42. half_t = tStats['50'];
  43. century_t = tStats['100'];
  44. highest_t = tStats['HS'];
  45. avg_t = tStats['Ave'];
  46.  
  47. isData = true;
  48.  
  49. setState(() {
  50. print('UI updated');
  51. });
  52. } else {
  53. print('something went wrong');
  54. }
  55. }
  56.  
  57. @override
  58. void initState() {
  59. var intIds = playerIds.map<int>((m) => m['pid'] as int).toList();
  60. for (int i = 0; i < intIds.length; i++) {
  61. FetchJson(intIds[i]);
  62. }
  63. }
  64.  
  65. @override
  66. Widget build(BuildContext context) {
  67. return Container(
  68. height: 700.0,
  69. child: ListView.builder(
  70. shrinkWrap: true,
  71. itemBuilder: (context, index) {
  72. return Card(
  73. child: Container(
  74. padding: EdgeInsets.all(8.0),
  75. height: MediaQuery.of(context).size.height - 84,
  76. width: MediaQuery.of(context).size.width,
  77. color: Colors.white30,
  78. child: Stack(
  79. children: <Widget>[profileDetails(), playerImage()],
  80. ),
  81. ),
  82. );
  83. },
  84. ),
  85. );
  86. }
Add Comment
Please, Sign In to add comment