• 12-09-2022, 17:39:20
    #1
    Merhaba iyi günler api bağlamada bir sorun yaşıyorum Kodlarım bunlar
    import 'dart:convert';
    import 'package:flutter/material.dart';
    import 'package:flutter_svg/flutter_svg.dart';
    import 'package:http/http.dart' as http;
    class TableScreen extends StatefulWidget {
      final String code;
      const TableScreen({Key key, this.code}) : super(key: key);
      @override
      _TableScreenState createState() => _TableScreenState();
    }
    class _TableScreenState extends State<TableScreen> {
      List _table;
      getTable() async {
        http.Response response = await http.get(
            'https://xxxx.items/daily_betting_tips',
            headers: {
              'X-RapidAPI-Host': 'xxxx..com',
              'X-RapidAPI-Key':
                  'XXXXXXX',
              "useQueryString": "true"
            });
        String body = response.body;
        Map data = jsonDecode(body);
        List table = data['Match'][0]['table'];
        setState(() {
          _table = table;
        });
      }
      Widget buildTable() {
        List<Widget> teams = [];
        for (var team in _table) {
          teams.add(
            Padding(
              padding: const EdgeInsets.all(10),
              child: Row(
                children: [
                  Expanded(
                    child: Row(
                      children: [
                        team['competitions'].toString().length > 1
                            ? Text(team['competitions'].toString() + ' - ')
                            : Text(" " + team['competitions'].toString() + ' - '),
                        Row(
                          children: [
                            SvgPicture.network(
                              team['home_team']['crestUrl'],
                              height: 30,
                              width: 30,
                            ),
                            team['home_team']['away_team'].toString().length > 11
                                ? Text(team['home_team']['away_team']
                                        .toString()
                                        .substring(0, 11) +
                                    '...')
                                : Text(team['home_team']['away_team'].toString()),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(team['game_prediction'].toString()),
                        Text(team['match_status'].toString()),
                        Text(team['match_date'].toString()),
                        Text(team['match_time'].toString()),
                        Text(team['sport_type'].toString()),
                        Text(team['odd_value'].toString()),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          );
        }
        return Column(
          children: teams,
        );
      }
      @override
      void initState() {
        super.initState();
        getTable();
      }
      @override
      Widget build(BuildContext context) {
        return _table == null
            ? Container(
                color: Colors.white,
                child: Center(
                  child: CircularProgressIndicator(
                    valueColor: AlwaysStoppedAnimation<Color>(
                      Color(0xFFe70066),
                    ),
                  ),
                ),
              )
            : Scaffold(
                body: Container(
                  decoration: BoxDecoration(
                      gradient: LinearGradient(
                    colors: [
                      const Color(0xffe84860),
                      const Color(0xffe70066),
                    ],
                    begin: const FractionalOffset(0.0, 0.0),
                    end: const FractionalOffset(0.0, 1.0),
                    stops: [0.0, 1.0],
                    tileMode: TileMode.clamp,
                  )),
                  child: ListView(
                    physics: const BouncingScrollPhysics(
                        parent: AlwaysScrollableScrollPhysics()),
                    children: [
                      SizedBox(
                        height: 20,
                      ),
                      Padding(
                        padding:
                            const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                        child: Row(
                          children: [
                            Expanded(
                              child: Row(
                                children: [
                                  Text(
                                    'Pos',
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                  SizedBox(
                                    width: 20,
                                  ),
                                  Text(
                                    'Club',
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                ],
                              ),
                            ),
                            Expanded(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    'PL',
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    'W',
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    'D',
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    'L',
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    'GD',
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    'Pts',
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      SizedBox(
                        height: 10,
                      ),
                      buildTable(),
                    ],
                  ),
                ),
              );
      }
    }
    Aldığım hatanın çıktısı
    NoSuchMethodError: '[]' Dynamic call of null. Receiver: null Arguments: [0]
    Yanlışımı düzeltebilecek birileri var ise şimdiden teşekkür ederim
  • 13-09-2022, 09:41:33
    #2
    Hangi satırda hata aldığınızı da yazsaydınız daha faydalı olurdu.
  • 13-09-2022, 10:22:11
    #3
    hocam günaydın
    List table = data['Match'][0]['table'];
    setState(() {
    _table = table;
    }); şu satırdaki bir sıkıntı var ve ya apiye bağlanamadım değerleri çekmiyor

    https://rapidapi.com/kevingitonga/ap...-betting-tips/ kullanmaya çalıştığım api bu