Created with <3 with dartpad.dev.
Last active
August 22, 2022 13:35
-
-
Save Quingsley/d9ae7ed0bb24f6aef947b69435e52503 to your computer and use it in GitHub Desktop.
working-with-json-data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:http/http.dart' show get; | |
void main() async { | |
final clientID = 'ha_NzNADHFGe6F3m0BDREK-WDj8mqABkeRTYW8JFhFk'; | |
final response = await get(Uri.parse('https://api.unsplash.com/photos?client_id=$clientID')); | |
//print(jsonDecode(response.body)); | |
var result = ImageModel.fromJson(jsonDecode(response.body)); | |
// print(result.url); | |
// print(result.tag); | |
print(result.imageUrl); | |
print(result.imageTag); | |
} | |
//model classes | |
class ImageModel{ | |
var counter = 0; | |
var imageUrl = []; | |
var imageTag = []; | |
ImageModel.fromJson(var parsedJson){ | |
for(counter ; counter < 10; counter++){ | |
imageUrl.add(parsedJson[counter]['urls']['regular']); | |
imageTag.add(parsedJson[0]["sponsorship"]["tagline"]); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment