1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-10 08:30:36 +01:00

58 lines
1.8 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
2019-12-12 14:02:48 +08:00
import 'package:git_touch/models/github.dart';
2019-09-03 16:51:25 +08:00
import 'package:git_touch/models/notification.dart';
2019-09-25 17:06:36 +08:00
import 'package:git_touch/scaffolds/list_stateful.dart';
2019-09-03 16:51:25 +08:00
import 'package:git_touch/utils/utils.dart';
2019-09-11 19:59:47 +08:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-03 16:51:25 +08:00
import 'package:provider/provider.dart';
2020-02-08 15:06:36 +08:00
import 'package:git_touch/widgets/event_item.dart';
2019-09-27 20:52:38 +08:00
import 'package:git_touch/models/auth.dart';
2019-03-10 16:09:26 +08:00
2020-02-07 14:17:05 +08:00
class GhNewsScreen extends StatefulWidget {
@override
2020-02-07 14:17:05 +08:00
GhNewsScreenState createState() => GhNewsScreenState();
}
2020-02-07 14:17:05 +08:00
class GhNewsScreenState extends State<GhNewsScreen> {
2019-09-03 16:51:25 +08:00
@override
initState() {
super.initState();
2020-01-14 12:33:18 +08:00
Future.microtask(() async {
2019-09-03 16:51:25 +08:00
// Check if there are unread notification items.
// 1 item is enough since count is not displayed for now.
2020-10-04 20:37:23 +08:00
var items = await context
.read<AuthModel>()
2020-02-19 01:00:16 +08:00
.ghClient
.getJSON('/notifications?per_page=1');
2019-09-03 16:51:25 +08:00
if (items is List && items.isNotEmpty) {
2020-10-04 20:37:23 +08:00
context.read<NotificationModel>().setCount(1);
2019-09-03 16:51:25 +08:00
}
});
}
@override
Widget build(context) {
2019-12-08 14:21:14 +08:00
return ListStatefulScaffold<GithubEvent, int>(
2019-09-11 19:59:47 +08:00
title: AppBarTitle('News'),
itemBuilder: (payload) => EventItem(payload),
fetch: (page) async {
2020-10-04 22:10:05 +08:00
page = page ?? 1;
final auth = context.read<AuthModel>();
final login = auth.activeAccount.login;
final events = await auth.ghClient.getJSON(
'/users/$login/received_events?page=$page&per_page=$pageSize',
convert: (vs) => [for (var v in vs) GithubEvent.fromJson(v)],
);
return ListPayload(
cursor: page + 1,
hasMore: events.length == pageSize,
items: events,
);
},
2019-02-03 14:42:50 +08:00
);
}
}