1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-20 20:13:55 +01:00
git-touch-android-ios-app/lib/screens/gitea_commits.dart

45 lines
1.4 KiB
Dart
Raw Normal View History

2020-02-01 08:21:42 +01:00
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitea.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/commit_item.dart';
import 'package:provider/provider.dart';
class GiteaCommitsScreen extends StatelessWidget {
final String owner;
final String name;
// final String branch; // TODO:
GiteaCommitsScreen(this.owner, this.name);
Future<ListPayload<GiteaCommit, int>> _query(BuildContext context,
[int page = 1]) async {
final auth = Provider.of<AuthModel>(context);
final res = await auth
.fetchGiteaWithPage('/repos/$owner/$name/commits?page=$page&limit=20');
return ListPayload(
cursor: res.cursor,
hasMore: res.hasMore,
items: (res.data as List).map((v) => GiteaCommit.fromJson(v)).toList(),
);
}
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GiteaCommit, int>(
title: AppBarTitle('Commits'),
onRefresh: () => _query(context),
onLoadMore: (cursor) => _query(context, cursor),
itemBuilder: (c) {
return CommitItem(
author: c.author?.login ?? c.commit.author.name,
avatarUrl: null,
createdAt: c.commit.author.date,
message: c.commit.message,
url: c.htmlUrl,
);
},
);
}
}