Skip to content

Instantly share code, notes, and snippets.

@castrors
Created February 9, 2018 20:19
Show Gist options
  • Save castrors/4afc6b7e7eee622e76ae7ffb4dab21c1 to your computer and use it in GitHub Desktop.
Save castrors/4afc6b7e7eee622e76ae7ffb4dab21c1 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(new MaterialApp(
home: new RepoListPage(),
));
}
class RepoListPage extends StatefulWidget {
@override
RepoListPageState createState() => new RepoListPageState();
}
class RepoListPageState extends State<RepoListPage> {
List data;
Future<String> getData() async {
var response = await http.get(
Uri.encodeFull("https://api.github.com/search/repositories?q=language:Java&sort=stars"),
headers: {
"Accept": "application/json"
}
);
this.setState(() {
data = JSON.decode(response.body)["items"];
});
print(data[1]["name"]);
return "Success!";
}
@override
void initState() {
this.getData();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Listviews"),
),
body: new ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return createListItem(data[index]);
},
),
);
}
Widget createListItem(data) => new Container(
padding: const EdgeInsets.all(32.0),
child: new Row(
children: [
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
new Container(
padding: const EdgeInsets.only(bottom: 8.0),
child: new Text(
data["name"],
style: new TextStyle(
fontWeight: FontWeight.bold,
),
),
),
new Text(
data["description"],
style: new TextStyle(
color: Colors.grey[500],
),
),
new Row(children: <Widget>[
new Icon(
Icons.content_copy,
color: Colors.red[500],
),
new Text('${data["forks_count"]}'),
new Icon(
Icons.star,
color: Colors.red[500],
),
new Text('${data["stargazers_count"]}'),
],)
],
),
),
// new Image.network(data["owner"]["avatar_url"]),
],
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment