1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-15 02:50:48 +01:00

81 lines
2.5 KiB
Dart
Raw Normal View History

2020-02-02 19:50:00 +08:00
import 'dart:convert';
2022-09-13 23:52:35 +08:00
2022-09-17 20:35:45 +08:00
import 'package:flutter/widgets.dart';
2020-02-02 19:50:00 +08:00
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/bitbucket.dart';
2022-09-13 23:52:35 +08:00
import 'package:git_touch/scaffolds/list_stateful.dart';
2022-09-17 20:35:45 +08:00
import 'package:git_touch/utils/utils.dart';
2020-02-02 19:50:00 +08:00
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/blob_view.dart';
import 'package:git_touch/widgets/object_tree.dart';
2022-09-13 23:52:35 +08:00
import 'package:git_touch/widgets/table_view.dart';
import 'package:path/path.dart';
2020-02-02 19:50:00 +08:00
import 'package:provider/provider.dart';
2022-09-13 23:52:35 +08:00
import 'package:universal_io/io.dart';
2020-02-02 19:50:00 +08:00
class BbObjectScreen extends StatelessWidget {
final String owner;
final String name;
final String ref;
2021-05-16 15:16:35 +08:00
final String? path;
2022-09-07 00:28:12 +08:00
const BbObjectScreen(this.owner, this.name, this.ref, {this.path});
2020-02-02 19:50:00 +08:00
@override
Widget build(BuildContext context) {
2020-02-02 23:02:58 +08:00
final auth = Provider.of<AuthModel>(context);
return ListStatefulScaffold<dynamic, String?>(
2020-02-02 19:50:00 +08:00
title: AppBarTitle(path ?? 'Files'),
fetch: (next) async {
final res = await auth.fetchBb(
next ?? '/repositories/$owner/$name/src/$ref/${path ?? ''}');
2020-02-02 19:50:00 +08:00
if (res.headers[HttpHeaders.contentTypeHeader] == 'text/plain') {
return ListPayload(
cursor: '',
hasMore: false,
items: [utf8.decode(res.bodyBytes)],
2020-02-02 19:50:00 +08:00
);
} else {
final v =
BbPagination.fromJson(json.decode(utf8.decode(res.bodyBytes)));
final items = [for (var t in v.values) BbTree.fromJson(t)];
items.sort((a, b) {
return sortByKey('dir', a.type, b.type);
});
return ListPayload(
cursor: v.next,
hasMore: v.next != null,
items: items,
);
2020-02-02 19:50:00 +08:00
}
},
itemBuilder: (pl) {
2020-02-02 19:50:00 +08:00
if (pl is String) {
return BlobView(path, text: pl);
} else if (pl is BbTree) {
2022-09-13 23:52:35 +08:00
return TableViewItemWidget(
createObjectTreeItem(
name: basename(pl.path),
type: pl.type,
// size: v.type == 'commit_file' ? v.size : null,
size: pl.size,
url: '/bitbucket/$owner/$name/src/$ref?path=${pl.path.urlencode}',
downloadUrl: pl.links!['self']['href'] as String?,
),
);
2020-02-02 19:50:00 +08:00
} else {
return Container();
2020-02-02 19:50:00 +08:00
}
},
actionBuilder: () {
2022-09-07 00:28:12 +08:00
return const ActionEntry(
iconData: Ionicons.cog,
url: '/choose-code-theme',
);
},
2020-02-02 19:50:00 +08:00
);
}
}