git-touch-android-ios-app/lib/screens/gh_events.dart

36 lines
1.2 KiB
Dart
Raw Normal View History

2020-10-04 15:04:23 +02:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:git_touch/models/github.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/widgets/event_item.dart';
import 'package:git_touch/models/auth.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
2020-10-04 15:04:23 +02:00
class GhEventsScreen extends StatelessWidget {
final String login;
GhEventsScreen(this.login);
@override
Widget build(context) {
return ListStatefulScaffold<GithubEvent, int>(
2021-05-16 09:16:35 +02:00
title: AppBarTitle(AppLocalizations.of(context)!.events),
2020-10-04 15:04:23 +02:00
itemBuilder: (payload) => EventItem(payload),
fetch: (page) async {
2020-10-04 16:10:05 +02:00
page = page ?? 1;
2021-05-16 09:16:35 +02:00
final events = await context.read<AuthModel>().ghClient!.getJSON(
2020-10-04 16:10:05 +02:00
'/users/$login/events?page=$page&per_page=$pageSize',
2021-05-30 19:07:31 +02:00
convert: (dynamic vs) =>
[for (var v in vs) GithubEvent.fromJson(v)]);
2020-10-04 16:10:05 +02:00
return ListPayload(
cursor: page + 1,
hasMore: events.length == pageSize,
items: events,
);
},
2020-10-04 15:04:23 +02:00
);
}
}