Created with <3 with dartpad.dev.
Last active
August 27, 2022 08:03
-
-
Save Quingsley/9a9904c78e399fb0a544eee6c916c42b to your computer and use it in GitHub Desktop.
playing with unsplash
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 'dart:math'; | |
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('This are the likes: $result'); | |
} | |
class ImageModel { | |
var url = ''; | |
var likes = 0; | |
var counter = 0 + Random().nextInt(10 - 0); | |
ImageModel(this.url); | |
ImageModel.fromJson(var parsedJson) { | |
url = parsedJson[counter]['urls']['regular']; | |
likes = parsedJson[counter]["likes"]; | |
} | |
@override | |
String toString() { | |
return '$likes'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment