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

55 lines
1.8 KiB
Dart
Raw Normal View History

2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
import 'package:git_touch/models/auth.dart';
2020-10-05 11:23:43 +02:00
import 'package:git_touch/models/gitea.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
2022-10-02 06:49:55 +02:00
import 'package:git_touch/widgets/repo_item.dart';
2022-09-17 14:35:45 +02:00
import 'package:provider/provider.dart';
2020-10-05 11:23:43 +02:00
import 'package:timeago/timeago.dart' as timeago;
class GtReposScreen extends StatelessWidget {
2022-09-06 18:28:12 +02:00
const GtReposScreen(String owner)
2020-10-05 11:23:43 +02:00
: api = '/users/$owner/repos',
title = 'Repositories';
2022-09-06 18:28:12 +02:00
const GtReposScreen.star(String owner)
2020-10-05 11:23:43 +02:00
: api = '/users/$owner/starred',
title = 'Stars';
2022-09-06 18:28:12 +02:00
const GtReposScreen.org(String owner)
2020-10-05 11:31:17 +02:00
: api = '/orgs/$owner/repos',
title = 'Repositories';
2022-09-06 18:28:12 +02:00
const GtReposScreen.forks(String owner, String repo)
: api = '/repos/$owner/$repo/forks',
title = 'Forks';
2022-09-21 18:28:21 +02:00
final String api;
final String title;
2020-10-05 11:23:43 +02:00
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GiteaRepository, int>(
title: AppBarTitle(title),
fetch: (page) async {
final res =
await context.read<AuthModel>().fetchGiteaWithPage(api, page: page);
2020-10-05 11:23:43 +02:00
return ListPayload(
cursor: res.cursor,
2020-10-05 11:23:43 +02:00
hasMore: res.hasMore,
items: [for (var v in res.data) GiteaRepository.fromJson(v)],
);
},
itemBuilder: (v) {
2022-10-02 06:49:55 +02:00
return RepoItem(
2021-05-16 09:16:35 +02:00
owner: v.owner!.login,
avatarUrl: v.owner!.avatarUrl,
2020-10-05 11:23:43 +02:00
name: v.name,
description: v.description,
starCount: v.starsCount,
forkCount: v.forksCount,
2021-05-16 09:16:35 +02:00
note: 'Updated ${timeago.format(v.updatedAt!)}',
url: '/gitea/${v.owner!.login}/${v.name}',
avatarLink: '/gitea/${v.owner!.login}',
2020-10-05 11:23:43 +02:00
);
},
);
}
}