mirror of
https://github.com/git-touch/git-touch
synced 2024-12-24 06:42:07 +01:00
46 lines
1.4 KiB
Dart
46 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import '../scaffolds/list.dart';
|
|
import '../widgets/event_item.dart';
|
|
import '../providers/settings.dart';
|
|
import '../utils/utils.dart';
|
|
|
|
class NewsScreen extends StatefulWidget {
|
|
@override
|
|
NewsScreenState createState() => NewsScreenState();
|
|
}
|
|
|
|
class NewsScreenState extends State<NewsScreen> {
|
|
Future<List<EventPayload>> fetchEvents(int page) async {
|
|
var settings = SettingsProvider.of(context);
|
|
var login = settings.activeLogin;
|
|
List data = await settings.getWithCredentials(
|
|
'/users/$login/received_events?page=$page&per_page=$pageSize');
|
|
// print(data);
|
|
return data
|
|
.map<EventPayload>((item) => EventPayload.fromJson(item))
|
|
.toList();
|
|
}
|
|
|
|
@override
|
|
Widget build(context) {
|
|
// FIXME: can't add generic type here. Don't know why
|
|
// type '(Event) => EventItem' is not a subtype of type '(dynamic) => Widget'
|
|
return ListScaffold(
|
|
title: Text('News'),
|
|
itemBuilder: (payload) => EventItem(payload),
|
|
onRefresh: () async {
|
|
var page = 1;
|
|
var items = await fetchEvents(page);
|
|
return ListPayload(
|
|
cursor: page + 1, hasMore: items.length == pageSize, items: items);
|
|
},
|
|
onLoadMore: (page) async {
|
|
var items = await fetchEvents(page);
|
|
return ListPayload(
|
|
cursor: page + 1, hasMore: items.length == pageSize, items: items);
|
|
},
|
|
);
|
|
}
|
|
}
|