Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:flutter_application_laurent/matchClass.dart';
- import 'package:flutter_svg/svg.dart';
- import 'package:http/http.dart' as http;
- class MyHomePage extends StatefulWidget {
- const MyHomePage({Key? key, required this.title}) : super(key: key);
- final String title;
- @override
- State<MyHomePage> createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- Future getMatch() async {
- final url = Uri.parse(
- "https://api.football-data.org/v2/matches?",
- );
- final response = await http.get(
- url,
- headers: {
- 'X-Auth-Token': 'ton apikey',
- 'Accept-Encoding': '',
- 'Accept': '*/*'
- },
- );
- Map<dynamic, dynamic> map = json.decode(response.body);
- return map;
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(widget.title),
- ),
- body: Center(
- child: FutureBuilder(
- future: getMatch(),
- // initialData: InitialData,
- builder: (BuildContext context, AsyncSnapshot snapshot) {
- return ListView.builder(
- itemCount: snapshot.data.length ?? 0,
- itemBuilder: (BuildContext context, int index) {
- // print(snapshot.data.length);
- // // print(snapshot.data[1].toString());
- // print(snapshot.data['matches'][index]['id']);
- // print(snapshot.data['matches'][index]['competition']['area']
- // ['ensignUrl']
- // .toString());
- return Card(
- shadowColor: Colors.red,
- elevation: 3.0,
- margin: EdgeInsets.all(20),
- child: Padding(
- padding: const EdgeInsets.all(10.0),
- child: Column(
- children: [
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: ClipRRect(
- borderRadius: BorderRadius.circular(20),
- child: SvgPicture.network(
- snapshot.data['matches'][index]['competition']
- ['area']['ensignUrl']
- .toString(),
- width: MediaQuery.of(context).size.width * 0.30,
- ),
- ),
- ),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- Text(
- snapshot.data['matches'][index]['homeTeam']
- ['name']
- .toString(),
- style: TextStyle(color: Colors.red),
- ),
- Text('-'),
- Text(snapshot.data['matches'][index]['awayTeam']
- ['name']
- .toString()),
- ],
- ),
- ),
- ],
- ),
- ),
- );
- },
- );
- },
- ),
- ),
- floatingActionButton: FloatingActionButton(
- onPressed: () {
- getMatch();
- },
- tooltip: 'Increment',
- child: const Icon(Icons.add),
- ),
- );
- }
- }
Add Comment
Please, Sign In to add comment