Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Quingsley
Last active August 27, 2022 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quingsley/9a9904c78e399fb0a544eee6c916c42b to your computer and use it in GitHub Desktop.
Save Quingsley/9a9904c78e399fb0a544eee6c916c42b to your computer and use it in GitHub Desktop.
playing with unsplash

playing with unsplash

Created with <3 with dartpad.dev.

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