1
0
mirror of https://github.com/git-touch/git-touch synced 2025-03-20 05:00:13 +01:00

130 lines
4.8 KiB
Dart
Raw Normal View History

2022-10-03 18:21:22 +08:00
import 'dart:convert';
2020-02-02 23:06:54 +08:00
2022-10-03 18:21:22 +08:00
import 'package:antd_mobile/antd_mobile.dart';
2020-02-02 18:58:05 +08:00
import 'package:filesize/filesize.dart';
2022-09-17 20:35:45 +08:00
import 'package:flutter/widgets.dart';
2022-09-14 01:19:52 +08:00
import 'package:flutter_gen/gen_l10n/S.dart';
2022-10-08 00:55:47 +08:00
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2020-02-02 18:58:05 +08:00
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/bitbucket.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/markdown_view.dart';
import 'package:git_touch/widgets/repo_header.dart';
2022-09-21 02:00:03 +08:00
import 'package:go_router/go_router.dart';
2020-02-02 18:58:05 +08:00
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
class BbRepoScreen extends StatelessWidget {
2022-09-22 00:28:21 +08:00
const BbRepoScreen(this.owner, this.name, {this.branch});
2020-02-02 18:58:05 +08:00
final String owner;
final String name;
2021-05-16 15:16:35 +08:00
final String? branch;
2020-02-02 18:58:05 +08:00
@override
Widget build(BuildContext context) {
2021-05-16 15:16:35 +08:00
return RefreshStatefulScaffold<Tuple3<BbRepo, String?, List<BbBranch>>>(
2022-10-08 01:06:03 +08:00
title: Text(AppLocalizations.of(context)!.repository),
fetch: () async {
2020-10-04 20:37:23 +08:00
final auth = context.read<AuthModel>();
2020-02-02 19:50:00 +08:00
final r = await auth.fetchBbJson('/repositories/$owner/$name');
final repo = BbRepo.fromJson(r);
final res = await auth.fetchBb(
2021-05-16 15:16:35 +08:00
'/repositories/$owner/$name/src/${repo.mainbranch!.name}/README.md');
2020-02-02 23:06:54 +08:00
final readme =
res.statusCode >= 400 ? null : utf8.decode(res.bodyBytes);
final branches = await auth
.fetchBbWithPage('/repositories/$owner/$name/refs/branches')
.then((v) {
2021-06-14 02:13:11 +08:00
return [for (var branch in v.items) BbBranch.fromJson(branch)];
});
return Tuple3(repo, readme, branches);
2020-02-02 18:58:05 +08:00
},
2021-01-31 15:49:28 +08:00
bodyBuilder: (t, _) {
2020-02-02 18:58:05 +08:00
final theme = Provider.of<ThemeModel>(context);
final p = t.item1;
final branches = t.item3;
2020-02-02 18:58:05 +08:00
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
RepoHeader(
avatarUrl: p.avatarUrl,
avatarLink: null,
2020-02-02 19:06:48 +08:00
owner: p.ownerLogin,
2020-02-02 18:58:05 +08:00
name: p.slug,
description: p.description,
homepageUrl: p.website,
),
CommonStyle.border,
2022-09-21 02:00:03 +08:00
AntList(
2022-09-22 23:37:06 +08:00
children: [
2022-09-21 02:00:03 +08:00
AntListItem(
prefix: const Icon(Octicons.code),
2022-09-14 01:19:52 +08:00
extra: Text(filesize(p.size)),
2022-09-21 02:00:03 +08:00
onClick: () {
context.push(
'/bitbucket/$owner/$name/src/${branch ?? p.mainbranch!.name}');
},
2022-09-22 23:37:06 +08:00
child: const Text('Code'),
2020-02-02 18:58:05 +08:00
),
2022-09-21 02:00:03 +08:00
AntListItem(
prefix: const Icon(Octicons.issue_opened),
2022-09-14 01:19:52 +08:00
child: const Text('Issues'),
2022-09-21 02:00:03 +08:00
onClick: () {
context.push('/bitbucket/$owner/$name/issues');
},
),
2022-09-21 02:00:03 +08:00
AntListItem(
prefix: const Icon(Octicons.git_pull_request),
2022-09-14 01:19:52 +08:00
child: const Text('Pull requests'),
2022-09-21 02:00:03 +08:00
onClick: () {
context.push('/bitbucket/$owner/$name/pulls');
},
),
2022-09-21 02:00:03 +08:00
AntListItem(
prefix: const Icon(Octicons.history),
2022-09-14 01:19:52 +08:00
child: const Text('Commits'),
2022-09-21 02:00:03 +08:00
onClick: () {
context.push(
'/bitbucket/$owner/$name/commits/${branch ?? p.mainbranch!.name}');
},
2020-02-02 18:58:05 +08:00
),
2022-09-21 02:00:03 +08:00
AntListItem(
prefix: const Icon(Octicons.git_branch),
2022-09-14 01:19:52 +08:00
extra: Text(
'${(branch ?? p.mainbranch!.name)!}${branches.length}'),
onClick: () async {
2021-06-14 01:23:16 +08:00
if (branches.length < 2) return;
2021-06-14 01:23:16 +08:00
await theme.showPicker(
context,
PickerGroupItem(
value: branch,
items: branches
.map((b) => PickerItem(b.name, text: b.name))
.toList(),
onClose: (ref) {
if (ref != branch) {
2022-09-23 01:50:45 +08:00
context.pushUrl(
'/bitbucket/$owner/$name?branch=$ref',
2021-06-14 01:23:16 +08:00
replace: true);
}
},
),
);
},
2022-09-22 23:37:06 +08:00
child: Text(AppLocalizations.of(context)!.branches),
2021-06-14 01:23:16 +08:00
),
2020-02-02 18:58:05 +08:00
],
),
CommonStyle.verticalGap,
2020-11-08 15:00:13 +08:00
if (t.item2 != null) MarkdownFlutterView(t.item2),
2020-02-02 18:58:05 +08:00
CommonStyle.verticalGap,
],
);
},
);
}
}