Created
February 22, 2018 01:49
-
-
Save castrors/558603c4666b84486f1a6d728faf540c to your computer and use it in GitHub Desktop.
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:async'; | |
import 'dart:convert'; | |
import 'package:flutter/material.dart'; | |
import 'package:http/http.dart' as http; | |
void main() { | |
runApp(new MaterialApp( | |
home: new RepoListPage(), | |
routes: <String, WidgetBuilder> { | |
'/detail' : (BuildContext context) => new PullRequestsPage(), | |
}, | |
)); | |
} | |
class PullRequestsPage extends StatefulWidget { | |
@override | |
PullRequestsPageState createState() => new PullRequestsPageState(); | |
} | |
class PullRequestsPageState extends State<PullRequestsPage> { | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text("Feijoada"), | |
), | |
body: new Text("acontece"), | |
); | |
} | |
} | |
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(context, data[index]); | |
}, | |
), | |
); | |
} | |
Widget createListItem(context, data) => new FlatButton( | |
onPressed: () { | |
Scaffold.of(context).showSnackBar(new SnackBar( | |
content: new Text(data["name"]), | |
)); | |
Navigator.of(context).pushNamed('/detail'); | |
}, | |
child: new Container( | |
padding: const EdgeInsets.all(16.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"], | |
maxLines: 3, | |
style: new TextStyle( | |
color: Colors.grey[500], | |
), | |
), | |
new Row( | |
children: <Widget>[ | |
new Icon( | |
Icons.content_copy, | |
color: Colors.yellow[700], | |
), | |
new Text('${data["forks_count"]}', | |
style: new TextStyle(color: Colors.yellow[700])), | |
new Icon( | |
Icons.star, | |
color: Colors.yellow[700], | |
), | |
new Text('${data["stargazers_count"]}', | |
style: new TextStyle(color: Colors.yellow[700])), | |
], | |
), | |
], | |
), | |
), | |
new Column( | |
children: <Widget>[ | |
new Image.network(data["owner"]["avatar_url"], | |
fit: BoxFit.cover, width: 64.0, height: 64.0), | |
new Text(data["owner"]["login"]) | |
], | |
) | |
], | |
), | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment