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

53 lines
1.7 KiB
Dart
Raw Normal View History

2020-10-17 12:09:36 +02:00
import 'package:flutter/material.dart';
import 'package:git_touch/models/gitee.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 GeReposScreen extends StatelessWidget {
final String api;
final String title;
2022-09-06 18:28:12 +02:00
const GeReposScreen(String owner)
2020-10-17 12:09:36 +02:00
: api = '/users/$owner/repos',
title = 'Repositories';
2022-09-06 18:28:12 +02:00
const GeReposScreen.star(String owner)
2020-10-17 12:09:36 +02:00
: api = '/users/$owner/starred',
title = 'Stars';
2022-09-06 18:28:12 +02:00
const GeReposScreen.forks(String owner, String name)
2020-10-17 13:06:11 +02:00
: api = '/repos/$owner/$name/forks',
title = 'Forks';
2020-10-17 12:09:36 +02:00
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GiteeRepo, int>(
title: AppBarTitle(title),
fetch: (page) async {
final res =
await context.read<AuthModel>().fetchGiteeWithPage(api, page: page);
return ListPayload(
cursor: res.cursor,
hasMore: res.hasMore,
items: [for (var v in res.data) GiteeRepo.fromJson(v)],
);
},
itemBuilder: (v) {
return RepositoryItem(
2021-05-16 09:16:35 +02:00
owner: v.namespace!.path,
avatarUrl: v.owner!.avatarUrl,
2020-10-17 12:09:36 +02:00
name: v.path,
description: v.description,
starCount: v.stargazersCount,
forkCount: v.forksCount,
2021-05-16 09:16:35 +02:00
note: 'Updated ${timeago.format(v.updatedAt!)}',
url: '/gitee/${v.namespace!.path}/${v.path}',
avatarLink: '/gitee/${v.namespace!.path}',
2020-10-17 12:09:36 +02:00
);
},
);
}
}