2018-07-05 16:08:19 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2019-01-26 15:10:18 +01:00
|
|
|
import 'package:git_flux/utils/utils.dart';
|
2019-01-28 14:32:01 +01:00
|
|
|
import 'package:git_flux/widgets/widgets.dart';
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-01-22 16:39:44 +01:00
|
|
|
class HomeScreen extends StatefulWidget {
|
2018-07-05 16:08:19 +02:00
|
|
|
@override
|
|
|
|
createState() {
|
2019-01-22 16:39:44 +01:00
|
|
|
return HomeScreenState();
|
2018-07-05 16:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 16:39:44 +01:00
|
|
|
class HomeScreenState extends State<HomeScreen> {
|
2019-01-23 09:50:51 +01:00
|
|
|
// final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
|
|
|
|
// GlobalKey<RefreshIndicatorState>();
|
2019-01-26 15:10:18 +01:00
|
|
|
int page = 1;
|
|
|
|
bool loading = false;
|
|
|
|
List<Event> events = [];
|
|
|
|
ScrollController _controller = ScrollController();
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-01-23 09:50:51 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
// FIXME: context hack
|
|
|
|
// Future.delayed(Duration(seconds: 0)).then((_) {
|
|
|
|
// EventProvider.of(context).update.add(true);
|
|
|
|
// });
|
2019-01-26 15:10:18 +01:00
|
|
|
_refresh();
|
|
|
|
_controller.addListener(() {
|
|
|
|
if (_controller.offset + 100 > _controller.position.maxScrollExtent &&
|
|
|
|
!_controller.position.outOfRange &&
|
|
|
|
!loading) {
|
|
|
|
_loadMore();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _refresh() async {
|
|
|
|
setState(() {
|
|
|
|
loading = true;
|
|
|
|
});
|
|
|
|
page = 1;
|
|
|
|
var items = await fetchEvents(page);
|
|
|
|
setState(() {
|
|
|
|
loading = false;
|
|
|
|
events = items;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _loadMore() async {
|
|
|
|
print('more');
|
|
|
|
setState(() {
|
|
|
|
loading = true;
|
|
|
|
});
|
|
|
|
page = page + 1;
|
|
|
|
var items = await fetchEvents(page);
|
|
|
|
setState(() {
|
|
|
|
loading = false;
|
|
|
|
events.addAll(items);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildBottomIndicator() {
|
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 15),
|
|
|
|
child: CupertinoActivityIndicator(radius: 12));
|
2018-07-05 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(context) {
|
2019-01-25 13:35:20 +01:00
|
|
|
// Navigator.of(context).pushNamed('/user');
|
2019-01-26 15:10:18 +01:00
|
|
|
// final eventBloc = EventProvider.of(context);
|
2019-01-23 09:50:51 +01:00
|
|
|
|
2018-07-05 16:08:19 +02:00
|
|
|
return CupertinoPageScaffold(
|
2019-01-26 15:10:18 +01:00
|
|
|
child: CustomScrollView(
|
|
|
|
controller: _controller,
|
|
|
|
slivers: <Widget>[
|
|
|
|
CupertinoSliverNavigationBar(
|
|
|
|
largeTitle: const Text('News'),
|
|
|
|
trailing: Icon(Octicons.settings),
|
|
|
|
),
|
|
|
|
CupertinoSliverRefreshControl(
|
|
|
|
onRefresh: _refresh,
|
|
|
|
),
|
|
|
|
SliverSafeArea(
|
|
|
|
top: false,
|
|
|
|
sliver: SliverList(
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(BuildContext context, int index) {
|
|
|
|
if (index == events.length) {
|
|
|
|
return _buildBottomIndicator();
|
|
|
|
} else {
|
|
|
|
return EventItem(events[index]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
childCount: events.length + 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2018-07-05 16:08:19 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|