AnoTest

FlutterFootball

Jan 19th, 2022 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.81 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_application_laurent/matchClass.dart';
  5. import 'package:flutter_svg/svg.dart';
  6. import 'package:http/http.dart' as http;
  7.  
  8. class MyHomePage extends StatefulWidget {
  9.   const MyHomePage({Key? key, required this.title}) : super(key: key);
  10.  
  11.   final String title;
  12.  
  13.   @override
  14.   State<MyHomePage> createState() => _MyHomePageState();
  15. }
  16.  
  17. class _MyHomePageState extends State<MyHomePage> {
  18.   Future getMatch() async {
  19.     final url = Uri.parse(
  20.       "https://api.football-data.org/v2/matches?",
  21.     );
  22.     final response = await http.get(
  23.       url,
  24.       headers: {
  25.         'X-Auth-Token': 'ton apikey',
  26.         'Accept-Encoding': '',
  27.         'Accept': '*/*'
  28.       },
  29.     );
  30.  
  31.     Map<dynamic, dynamic> map = json.decode(response.body);
  32.  
  33.     return map;
  34.   }
  35.  
  36.   @override
  37.   Widget build(BuildContext context) {
  38.     return Scaffold(
  39.       appBar: AppBar(
  40.         title: Text(widget.title),
  41.       ),
  42.       body: Center(
  43.         child: FutureBuilder(
  44.           future: getMatch(),
  45.           // initialData: InitialData,
  46.           builder: (BuildContext context, AsyncSnapshot snapshot) {
  47.             return ListView.builder(
  48.               itemCount: snapshot.data.length ?? 0,
  49.               itemBuilder: (BuildContext context, int index) {
  50.                 // print(snapshot.data.length);
  51.                 // // print(snapshot.data[1].toString());
  52.                 // print(snapshot.data['matches'][index]['id']);
  53.                 // print(snapshot.data['matches'][index]['competition']['area']
  54.                 //         ['ensignUrl']
  55.                 //     .toString());
  56.  
  57.                 return Card(
  58.                   shadowColor: Colors.red,
  59.                   elevation: 3.0,
  60.                   margin: EdgeInsets.all(20),
  61.                   child: Padding(
  62.                     padding: const EdgeInsets.all(10.0),
  63.                     child: Column(
  64.                       children: [
  65.                         Padding(
  66.                           padding: const EdgeInsets.all(8.0),
  67.                           child: ClipRRect(
  68.                             borderRadius: BorderRadius.circular(20),
  69.                             child: SvgPicture.network(
  70.                               snapshot.data['matches'][index]['competition']
  71.                                       ['area']['ensignUrl']
  72.                                   .toString(),
  73.                               width: MediaQuery.of(context).size.width * 0.30,
  74.                             ),
  75.                           ),
  76.                         ),
  77.                         Padding(
  78.                           padding: const EdgeInsets.all(8.0),
  79.                           child: Row(
  80.                             mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  81.                             children: [
  82.                               Text(
  83.                                 snapshot.data['matches'][index]['homeTeam']
  84.                                         ['name']
  85.                                     .toString(),
  86.                                 style: TextStyle(color: Colors.red),
  87.                               ),
  88.                               Text('-'),
  89.                               Text(snapshot.data['matches'][index]['awayTeam']
  90.                                       ['name']
  91.                                   .toString()),
  92.                             ],
  93.                           ),
  94.                         ),
  95.                       ],
  96.                     ),
  97.                   ),
  98.                 );
  99.               },
  100.             );
  101.           },
  102.         ),
  103.       ),
  104.       floatingActionButton: FloatingActionButton(
  105.         onPressed: () {
  106.           getMatch();
  107.         },
  108.         tooltip: 'Increment',
  109.         child: const Icon(Icons.add),
  110.       ),
  111.     );
  112.   }
  113. }
  114.  
Add Comment
Please, Sign In to add comment