mirror of
https://github.com/git-touch/git-touch
synced 2025-02-28 09:17:56 +01:00
feat(gitee): add blob screen
This commit is contained in:
parent
6870aa6ff1
commit
2bdfb3dfe1
lib
@ -114,3 +114,11 @@ class GiteeTreeItem {
|
|||||||
factory GiteeTreeItem.fromJson(Map<String, dynamic> json) =>
|
factory GiteeTreeItem.fromJson(Map<String, dynamic> json) =>
|
||||||
_$GiteeTreeItemFromJson(json);
|
_$GiteeTreeItemFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||||
|
class GiteeBlob {
|
||||||
|
String content;
|
||||||
|
GiteeBlob();
|
||||||
|
factory GiteeBlob.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$GiteeBlobFromJson(json);
|
||||||
|
}
|
||||||
|
@ -191,3 +191,11 @@ Map<String, dynamic> _$GiteeTreeItemToJson(GiteeTreeItem instance) =>
|
|||||||
'sha': instance.sha,
|
'sha': instance.sha,
|
||||||
'size': instance.size,
|
'size': instance.size,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GiteeBlob _$GiteeBlobFromJson(Map<String, dynamic> json) {
|
||||||
|
return GiteeBlob()..content = json['content'] as String;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _$GiteeBlobToJson(GiteeBlob instance) => <String, dynamic>{
|
||||||
|
'content': instance.content,
|
||||||
|
};
|
||||||
|
@ -6,6 +6,7 @@ import 'package:git_touch/screens/bb_issues.dart';
|
|||||||
import 'package:git_touch/screens/bb_pulls.dart';
|
import 'package:git_touch/screens/bb_pulls.dart';
|
||||||
import 'package:git_touch/screens/bb_user.dart';
|
import 'package:git_touch/screens/bb_user.dart';
|
||||||
import 'package:git_touch/screens/code_theme.dart';
|
import 'package:git_touch/screens/code_theme.dart';
|
||||||
|
import 'package:git_touch/screens/ge_blob.dart';
|
||||||
import 'package:git_touch/screens/ge_commits.dart';
|
import 'package:git_touch/screens/ge_commits.dart';
|
||||||
import 'package:git_touch/screens/ge_repo.dart';
|
import 'package:git_touch/screens/ge_repo.dart';
|
||||||
import 'package:git_touch/screens/ge_repos.dart';
|
import 'package:git_touch/screens/ge_repos.dart';
|
||||||
@ -388,6 +389,7 @@ class GiteeRouter {
|
|||||||
GiteeRouter.forks,
|
GiteeRouter.forks,
|
||||||
GiteeRouter.commits,
|
GiteeRouter.commits,
|
||||||
GiteeRouter.tree,
|
GiteeRouter.tree,
|
||||||
|
GiteeRouter.blob,
|
||||||
];
|
];
|
||||||
static final user = RouterScreen('/:login', (context, p) {
|
static final user = RouterScreen('/:login', (context, p) {
|
||||||
final login = p['login'].first;
|
final login = p['login'].first;
|
||||||
@ -431,4 +433,15 @@ class GiteeRouter {
|
|||||||
parameters['sha'].first);
|
parameters['sha'].first);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
static final blob = RouterScreen(
|
||||||
|
'/:owner/:name/blob/:sha',
|
||||||
|
(context, parameters) {
|
||||||
|
return GeBlobScreen(
|
||||||
|
parameters['owner'].first,
|
||||||
|
parameters['name'].first,
|
||||||
|
parameters['sha'].first,
|
||||||
|
parameters['path'].first,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
32
lib/screens/ge_blob.dart
Normal file
32
lib/screens/ge_blob.dart
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:git_touch/models/auth.dart';
|
||||||
|
import 'package:git_touch/models/gitee.dart';
|
||||||
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||||
|
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:provider/provider.dart';
|
||||||
|
|
||||||
|
class GeBlobScreen extends StatelessWidget {
|
||||||
|
final String owner;
|
||||||
|
final String name;
|
||||||
|
final String sha;
|
||||||
|
final String path;
|
||||||
|
GeBlobScreen(this.owner, this.name, this.sha, this.path);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return RefreshStatefulScaffold<String>(
|
||||||
|
title: AppBarTitle('File'),
|
||||||
|
fetch: () async {
|
||||||
|
final auth = context.read<AuthModel>();
|
||||||
|
final res = await auth.fetchGitee('/repos/$owner/$name/git/blobs/$sha');
|
||||||
|
return GiteeBlob.fromJson(res).content;
|
||||||
|
},
|
||||||
|
action: ActionEntry(iconData: Icons.settings, url: '/choose-code-theme'),
|
||||||
|
bodyBuilder: (content, _) {
|
||||||
|
return BlobView(path, base64Text: content);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -40,9 +40,9 @@ class GeTreeScreen extends StatelessWidget {
|
|||||||
url: (() {
|
url: (() {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 'tree':
|
case 'tree':
|
||||||
return '/gitee/$owner/$name/tree/${item.sha}';
|
return '/gitee/$owner/$name/tree/${item.sha}?path=${item.path.urlencode}';
|
||||||
case 'blob':
|
case 'blob':
|
||||||
return '/gitee/$owner/$name/blob/${item.sha}';
|
return '/gitee/$owner/$name/blob/${item.sha}?path=${item.path.urlencode}';
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user