mirror of
https://github.com/git-touch/git-touch
synced 2025-01-05 12:27:11 +01:00
Add more components of home page
This commit is contained in:
parent
19bc824b32
commit
dfb32cc0fd
@ -1,34 +1,72 @@
|
||||
// import 'dart:async';
|
||||
import 'dart:async';
|
||||
// import 'dart:convert';
|
||||
import '../utils.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'home/event.dart';
|
||||
|
||||
class IosHomeTab extends StatelessWidget {
|
||||
class IosHomeTab extends StatefulWidget {
|
||||
@override
|
||||
createState() {
|
||||
return new IosHomeTabState();
|
||||
}
|
||||
}
|
||||
|
||||
class IosHomeTabState extends State<IosHomeTab> {
|
||||
int page = 1;
|
||||
List<Event> events = [];
|
||||
|
||||
loadFirst() async {
|
||||
events = await fetchEvents();
|
||||
page = 1;
|
||||
return events;
|
||||
}
|
||||
|
||||
loadMore() async {
|
||||
events.addAll(await fetchEvents(page + 1));
|
||||
page++;
|
||||
return events;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(context) {
|
||||
return new FutureBuilder(
|
||||
future: fetchEvents(),
|
||||
future: loadFirst(),
|
||||
builder: (context, snapshot) {
|
||||
Widget widget;
|
||||
if (snapshot.hasData) {
|
||||
List<Event> events = snapshot.data;
|
||||
widget = new ListView(
|
||||
padding: new EdgeInsets.all(8.0),
|
||||
// itemExtent: 20.0,
|
||||
children: events.map((event) {
|
||||
switch (event.type) {
|
||||
case 'IssuesEvent':
|
||||
return new IssuesEvent(event);
|
||||
case 'PushEvent':
|
||||
return new PushEvent(event);
|
||||
case 'PullRequestEvent':
|
||||
return new PullRequestEvent(event);
|
||||
default:
|
||||
return new Text('');
|
||||
}
|
||||
}).toList(),
|
||||
// List<Event> events = snapshot.data;
|
||||
widget = new CustomScrollView(
|
||||
slivers: [
|
||||
new CupertinoRefreshControl(
|
||||
onRefresh: () {
|
||||
return loadFirst();
|
||||
},
|
||||
),
|
||||
new SliverSafeArea(
|
||||
// top: true,
|
||||
sliver: new SliverList(
|
||||
delegate: new SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
var event = events[index];
|
||||
switch (event.type) {
|
||||
case 'IssuesEvent':
|
||||
return new IssuesEvent(event);
|
||||
case 'PushEvent':
|
||||
return new PushEvent(event);
|
||||
case 'PullRequestEvent':
|
||||
return new PullRequestEvent(event);
|
||||
case 'WatchEvent':
|
||||
return new WatchEvent(event);
|
||||
default:
|
||||
return new Text('Not implement yet');
|
||||
}
|
||||
},
|
||||
childCount: 30,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
widget = new Text("${snapshot.error}");
|
||||
@ -37,14 +75,6 @@ class IosHomeTab extends StatelessWidget {
|
||||
}
|
||||
|
||||
return widget;
|
||||
// return new CustomScrollView(slivers: [
|
||||
// new CupertinoRefreshControl(
|
||||
// onRefresh: () {
|
||||
// return fetchEvents();
|
||||
// },
|
||||
// ),
|
||||
// // new CupertinoActivityIndicator(),
|
||||
// ]);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -142,3 +142,29 @@ class IssueCommentEvent extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WatchEvent extends StatelessWidget {
|
||||
final Event event;
|
||||
WatchEvent(this.event);
|
||||
|
||||
@override
|
||||
build(ctx) {
|
||||
return new Row(
|
||||
children: <Widget>[
|
||||
new _Avatar(event.avatar),
|
||||
new Expanded(
|
||||
child: new RichText(
|
||||
text: new TextSpan(
|
||||
style: new TextStyle(color: CupertinoColors.black),
|
||||
children: [
|
||||
_strong(event.actor),
|
||||
new TextSpan(text: ' ${event.payload['action']} '),
|
||||
_strong(event.repo),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ class Event {
|
||||
// }
|
||||
}
|
||||
|
||||
Future<List<Event>> fetchEvents() async {
|
||||
Future<List<Event>> fetchEvents([int page = 1]) async {
|
||||
final res = await http.get(
|
||||
prefix + '/users/pd4d10/received_events/public',
|
||||
prefix + '/users/pd4d10/received_events/public?page=$page',
|
||||
headers: {HttpHeaders.AUTHORIZATION: 'token $token'},
|
||||
);
|
||||
List<dynamic> resJson = json.decode(res.body);
|
||||
|
Loading…
Reference in New Issue
Block a user