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

44 lines
1.4 KiB
Dart
Raw Normal View History

2021-01-23 15:08:05 +01:00
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gogs.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';
import '../generated/l10n.dart';
class GoCommitsScreen extends StatelessWidget {
final String owner;
final String name;
final String branch;
GoCommitsScreen(this.owner, this.name, {this.branch = 'master'});
// TODO: API only returns most recent commit. No provision for all commits.
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GogsCommit, int>(
title: AppBarTitle(S.of(context).commits),
fetch: (page) async {
final res = await context.read<AuthModel>().fetchGogsWithPage(
'/repos/$owner/$name/commits/$branch',
page: page);
return ListPayload(
cursor: res.cursor,
hasMore: res.hasMore,
items: [GogsCommit.fromJson(res.data)],
);
},
itemBuilder: (c) {
return CommitItem(
author: c.author?.username ?? c.commit.author.name,
avatarUrl: c.author.avatarUrl,
avatarLink: '/gogs/${c.author.username}',
createdAt: c.commit.author.date,
message: c.commit.message,
url: c.htmlUrl,
);
},
);
}
}