Advertisement
Guest User

Untitled

a guest
May 5th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.25 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'dart:convert';
  4. import 'dart:io';
  5. import 'package:http/http.dart' as http;
  6.  
  7.  
  8. class Pc extends StatelessWidget {
  9.  
  10.   @override
  11.   Widget build(BuildContext context) {
  12.     return new FutureBuilder(
  13.       future: getPcGames(),
  14.       builder: (context, snapshot) {
  15.         if(snapshot.hasData){
  16.           var pcData = snapshot.data;
  17.           return new ListView.builder(
  18.             itemBuilder: (context, position) => new ListTile(
  19.                 title: new Text("${pcData[position]['name']}")
  20.             ),
  21.             itemCount: pcData.length,
  22.           );
  23.         } else{
  24.           return Center(
  25.             child: new CircularProgressIndicator(
  26.               backgroundColor: Colors.pink
  27.             )
  28.           );
  29.         }
  30.       }
  31.     );
  32.   }
  33. }
  34.  
  35. Future<List> getPcGames() async{
  36.   String url = "https://api-endpoint.igdb.com/games/?fields=name,"
  37.       "release_dates,screenshots&limit=50&order=release_dates"
  38.       ".date:dsc&filter[platforms][eq]=48";
  39.   http.Response response = await http.get(Uri.encodeFull(url), headers: {
  40.     "user-key": "XXXXXXXXX",
  41.     "Accept": "application/json"
  42.   });
  43.   //print(response.body);
  44.   return json.decode(response.body);
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement