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

40 lines
1.3 KiB
Dart
Raw Normal View History

2020-02-01 11:51:33 +01:00
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.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/widgets/user_item.dart';
import 'package:provider/provider.dart';
2020-02-07 15:20:06 +01:00
class GtOrgsScreen extends StatelessWidget {
2020-02-01 11:51:33 +01:00
// final String branch; // TODO:
Future<ListPayload<GiteaOrg, int>> _query(BuildContext context,
[int page = 1]) async {
final auth = Provider.of<AuthModel>(context);
2020-02-26 14:28:49 +01:00
final res = await auth.fetchGiteaWithPage('/orgs?limit=20&page=$page');
// TODO: https://github.com/go-gitea/gitea/issues/10199
2020-02-01 11:51:33 +01:00
return ListPayload(
2020-02-26 14:28:49 +01:00
cursor: page + 1,
hasMore: (res.data as List).length == 20,
2020-02-01 11:51:33 +01:00
items: (res.data as List).map((v) => GiteaOrg.fromJson(v)).toList(),
);
}
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GiteaOrg, int>(
title: AppBarTitle('Organizations'),
onRefresh: () => _query(context),
onLoadMore: (cursor) => _query(context, cursor),
itemBuilder: (v) {
return UserItem(
avatarUrl: v.avatarUrl,
login: v.username,
bio: Text(v.description ?? ''),
2020-02-01 12:07:51 +01:00
url: '/gitea/${v.username}?org=1',
2020-02-01 11:51:33 +01:00
);
},
);
}
}