繁体   English   中英

Flutter - 如何从 IGDB API 检索和显示数据?

[英]Flutter - How to retrieve and show data from IGDB API?

我有一个将成为视频游戏集合的应用程序,ApiHelper class 帮助我从 IGDB API 获取数据,我正在使用 lib igdb_client从 IGDB 搜索和检索数据,但我不知道如何显示数据,通过到 map 变量或其他东西,以显示在屏幕上。

我试图阅读 IGDB 文档,但这是我第一次使用 API,我不明白如何使用。

我创建了一个名为 Game 的 class 来接收数据。 printResponse 方法打印一个 map ,其数据如下:

I/flutter (26322): zelda
I/flutter (26322): {
I/flutter (26322):   "status": 200,
I/flutter (26322):   "error": null,
I/flutter (26322):   "data": [
I/flutter (26322):     {
I/flutter (26322):       "id": 1025,
I/flutter (26322):       "cover": 81860,
I/flutter (26322):       "name": "Zelda II: The Adventure of Link",
I/flutter (26322):       "screenshots": [
I/flutter (26322):         19444,
I/flutter (26322):         179229,
I/flutter (26322):         179230,
I/flutter (26322):         179231,
I/flutter (26322):         179232,
I/flutter (26322):         179233,
I/flutter (26322):         179234,
I/flutter (26322):         179235,
I/flutter (26322):         179236
I/flutter (26322):       ]
I/flutter (26322):     },


import 'package:igdb_client/igdb_client.dart';

class ApiHelper {

  static const String API_KEY = 'xxxxxxx';

  static void apiSearch(String text) async {

    var client = new IGDBClient("xxxx", API_KEY);

    var gamesResponse = await client.games(new IGDBRequestParameters(
      search: text,
      fields: [ "id", "name", "storyline", "screenshots", "cover" ],

    ));


    if (gamesResponse.isSuccess()) {

      printResponse(gamesResponse);


    } else {
      print("ERROR");
    }

  }

  static printResponse(IGDBResponse resp) {
    print(IGDBHelpers.getPrettyStringFromMap(resp.toMap()));
  }

}

class Game {

  String id;
  String name;
  String cover;
  String storyline;
  List<String> screenshots;

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM