2019-01-31 07:20:48 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-02-03 07:42:50 +01:00
|
|
|
import '../widgets/list_scaffold.dart';
|
2019-01-31 07:20:48 +01:00
|
|
|
import '../widgets/event_item.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import '../providers/settings.dart';
|
2019-01-31 07:20:48 +01:00
|
|
|
import '../utils/utils.dart';
|
|
|
|
|
|
|
|
class NewsScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
NewsScreenState createState() => NewsScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class NewsScreenState extends State<NewsScreen> {
|
|
|
|
int page = 1;
|
|
|
|
List<Event> _events = [];
|
2019-01-31 08:23:52 +01:00
|
|
|
|
2019-02-07 09:46:21 +01:00
|
|
|
Future<List<Event>> fetchEvents(int page) async {
|
|
|
|
var settings = SettingsProvider.of(context);
|
|
|
|
var login = settings.activeLogin;
|
|
|
|
List data = await settings
|
|
|
|
.getWithCredentials('/users/$login/received_events?page=$page');
|
2019-02-07 07:35:19 +01:00
|
|
|
return data.map<Event>((item) => Event.fromJSON(item)).toList();
|
|
|
|
}
|
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
@override
|
|
|
|
Widget build(context) {
|
2019-02-03 07:42:50 +01:00
|
|
|
return ListScaffold(
|
2019-02-05 13:57:05 +01:00
|
|
|
title: Text('News'),
|
2019-02-03 07:42:50 +01:00
|
|
|
itemCount: _events.length,
|
|
|
|
itemBuilder: (context, index) => EventItem(_events[index]),
|
|
|
|
onRefresh: () async {
|
|
|
|
page = 1;
|
2019-02-07 09:46:21 +01:00
|
|
|
var items = await fetchEvents(page);
|
2019-02-03 07:42:50 +01:00
|
|
|
setState(() {
|
|
|
|
_events = items;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onLoadMore: () async {
|
|
|
|
page = page + 1;
|
2019-02-07 09:46:21 +01:00
|
|
|
var items = await fetchEvents(page);
|
2019-02-03 07:42:50 +01:00
|
|
|
setState(() {
|
|
|
|
_events.addAll(items);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2019-01-31 07:20:48 +01:00
|
|
|
}
|
|
|
|
}
|