Repository list sort by date
All checks were successful
ci/woodpecker/push/flutterBuild Pipeline was successful

This commit is contained in:
Balazs Toldi 2022-05-09 12:14:50 +02:00
parent 69704a20f0
commit 29a89b951c
Signed by: Bazsalanszky
GPG key ID: 6C7D440036F99D58
4 changed files with 9 additions and 6 deletions

View file

@ -21,7 +21,7 @@ class RepoBloc extends Bloc<RepoEvent, RepoState> {
if (state.hasReachedMax) return;
try {
if (state.status == RepoStatus.initial) {
final repos = await giteaService.getUserRepositories();
final repos = await giteaService.getUserRepositories(1,100);
return emit(state.copyWith(
status: RepoStatus.success,
repos: repos,
@ -30,7 +30,7 @@ class RepoBloc extends Bloc<RepoEvent, RepoState> {
error_message: null,
));
}
final repos = await giteaService.getUserRepositories(state.loadedPages+1);
final repos = await giteaService.getUserRepositories(state.loadedPages+1,100);
emit(repos.isEmpty
? state.copyWith(hasReachedMax: true)
: state.copyWith(

View file

@ -29,7 +29,7 @@ class Repository extends Equatable {
String? defaultBranch;
bool? archived;
String? createdAt;
String? updatedAt;
DateTime? updatedAt;
Permissions? permissions;
bool? hasIssues;
InternalTracker? internalTracker;
@ -121,7 +121,7 @@ class Repository extends Equatable {
defaultBranch = json['default_branch'];
archived = json['archived'];
createdAt = json['created_at'];
updatedAt = json['updated_at'];
updatedAt = DateTime.parse(json['updated_at']);
permissions = json['permissions'] != null
? Permissions.fromJson(json['permissions'])
: null;

View file

@ -34,9 +34,12 @@ class GiteaService {
);
if (response.statusCode == 200) {
final body = json.decode(response.body) as List;
return body.map((dynamic json) {
var result = body.map((dynamic json) {
return Repository.fromJson(json);
}).toList();
result.sort((a,b) => -1*a.updatedAt!.compareTo(b.updatedAt!));
return result;
}
throw Exception('error fetching posts');
}

View file

@ -92,7 +92,7 @@ class RepoListItem extends StatelessWidget {
final textTheme = Theme.of(context).textTheme;
return Material(
child: ListTile(
leading: Text('${post.id}', style: textTheme.caption),
leading: Text('${post.updatedAt!.toString()}', style: textTheme.caption),
title: Text(post.name),
isThreeLine: true,
subtitle: Text(post.owner.username!),