-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathbb_object.dart
More file actions
76 lines (71 loc) · 2.4 KB
/
Copy pathbb_object.dart
File metadata and controls
76 lines (71 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import 'dart:convert';
import 'package:flutter/widgets.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/bitbucket.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/blob_view.dart';
import 'package:git_touch/widgets/object_tree.dart';
import 'package:path/path.dart' as p;
import 'package:provider/provider.dart';
import 'package:universal_io/io.dart';
class BbObjectScreen extends StatelessWidget {
const BbObjectScreen(this.owner, this.name, this.ref, {this.path});
final String owner;
final String name;
final String ref;
final String? path;
@override
Widget build(BuildContext context) {
final auth = Provider.of<AuthModel>(context);
return ListStatefulScaffold<dynamic, String?>(
title: Text(path ?? 'Files'),
fetch: (next) async {
final res = await auth.fetchBb(
next ?? '/repositories/$owner/$name/src/$ref/${path ?? ''}');
if (res.headers[HttpHeaders.contentTypeHeader] == 'text/plain') {
return ListPayload(
cursor: '',
hasMore: true,
items: [utf8.decode(res.bodyBytes)],
);
} 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,
);
}
},
itemBuilder: (pl) {
if (pl is String) {
return BlobView(path, text: pl);
} else if (pl is BbTree) {
return createObjectTreeItem(
name: p.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?,
);
} else {
return Container();
}
},
actionBuilder: () {
return const ActionEntry(
iconData: Ionicons.cog,
url: '/choose-code-theme',
);
},
);
}
}