2020-10-05 11:23:43 +02:00
|
|
|
import 'package:flutter/material.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/models/auth.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:git_touch/widgets/repository_item.dart';
|
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
|
|
|
|
|
|
|
class GtReposScreen extends StatelessWidget {
|
|
|
|
final String api;
|
|
|
|
final String title;
|
|
|
|
|
2020-10-05 12:20:00 +02:00
|
|
|
GtReposScreen(String owner)
|
2020-10-05 11:23:43 +02:00
|
|
|
: api = '/users/$owner/repos',
|
|
|
|
title = 'Repositories';
|
2020-10-05 12:20:00 +02:00
|
|
|
GtReposScreen.star(String owner)
|
2020-10-05 11:23:43 +02:00
|
|
|
: api = '/users/$owner/starred',
|
|
|
|
title = 'Stars';
|
2020-10-05 12:20:00 +02:00
|
|
|
GtReposScreen.org(String owner)
|
2020-10-05 11:31:17 +02:00
|
|
|
: api = '/orgs/$owner/repos',
|
|
|
|
title = 'Repositories';
|
2020-10-05 12:20:00 +02:00
|
|
|
GtReposScreen.forks(String owner, String repo)
|
|
|
|
: api = '/repos/$owner/$repo/forks',
|
|
|
|
title = 'Forks';
|
2020-10-05 11:23:43 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListStatefulScaffold<GiteaRepository, int>(
|
|
|
|
title: AppBarTitle(title),
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: (page) async {
|
2020-10-06 05:54:35 +02:00
|
|
|
final res =
|
|
|
|
await context.read<AuthModel>().fetchGiteaWithPage(api, page: page);
|
2020-10-05 11:23:43 +02:00
|
|
|
return ListPayload(
|
2020-10-06 05:54:35 +02:00
|
|
|
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) {
|
|
|
|
return RepositoryItem(
|
|
|
|
owner: v.owner.login,
|
|
|
|
avatarUrl: v.owner.avatarUrl,
|
|
|
|
name: v.name,
|
|
|
|
description: v.description,
|
|
|
|
starCount: v.starsCount,
|
|
|
|
forkCount: v.forksCount,
|
|
|
|
note: 'Updated ${timeago.format(v.updatedAt)}',
|
|
|
|
url: '/gitea/${v.owner.login}/${v.name}',
|
|
|
|
avatarLink: '/gitea/${v.owner.login}',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|