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

View file

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

View file

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

View file

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