mirror of
https://github.com/git-touch/git-touch
synced 2025-01-19 02:40:05 +01:00
improvement(github): avoid fetch images data again
This commit is contained in:
parent
d02b4800ca
commit
14c6944481
@ -16,6 +16,7 @@ final objectRouter = RouterScreen('/:owner/:name/blob/:ref', (context, params) {
|
||||
params['name'].first,
|
||||
params['ref'].first,
|
||||
path: params['path']?.first,
|
||||
raw: params['raw']?.first,
|
||||
);
|
||||
});
|
||||
|
||||
@ -24,7 +25,8 @@ class ObjectScreen extends StatelessWidget {
|
||||
final String name;
|
||||
final String ref;
|
||||
final String path;
|
||||
ObjectScreen(this.owner, this.name, this.ref, {this.path});
|
||||
final String raw;
|
||||
ObjectScreen(this.owner, this.name, this.ref, {this.path, this.raw});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -32,6 +34,12 @@ class ObjectScreen extends StatelessWidget {
|
||||
// canRefresh: !_isImage, // TODO:
|
||||
title: AppBarTitle(path == null ? 'Files' : path),
|
||||
fetchData: () async {
|
||||
// Do not request again for images
|
||||
if (path != null &&
|
||||
raw != null &&
|
||||
['png', 'jpg', 'jpeg', 'gif', 'webp'].contains(path.ext))
|
||||
return {'download_url': raw};
|
||||
|
||||
final suffix = path == null ? '' : '/$path';
|
||||
final res = await Provider.of<AuthModel>(context)
|
||||
.getWithCredentials('/repos/$owner/$name/contents$suffix?ref=$ref');
|
||||
@ -54,10 +62,17 @@ class ObjectScreen extends StatelessWidget {
|
||||
return ObjectTree(
|
||||
items: items.map((v) {
|
||||
// if (item.type == 'commit') return null;
|
||||
final uri = Uri(
|
||||
path: '/$owner/$name/blob/$ref',
|
||||
queryParameters: {
|
||||
'path': v.path,
|
||||
...(v.downloadUrl == null ? {} : {'raw': v.downloadUrl}),
|
||||
},
|
||||
).toString();
|
||||
return ObjectTreeItem(
|
||||
name: v.name,
|
||||
type: v.type,
|
||||
url: '/$owner/$name/blob/$ref?path=${v.path.urlencode}',
|
||||
url: uri.toString(),
|
||||
downloadUrl: v.downloadUrl,
|
||||
size: v.type == 'file' ? v.size : null,
|
||||
);
|
||||
|
@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_highlight/theme_map.dart';
|
||||
import 'package:git_touch/models/code.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/widgets/loading.dart';
|
||||
import 'package:git_touch/widgets/markdown_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_highlight/flutter_highlight.dart';
|
||||
@ -38,7 +39,14 @@ class BlobView extends StatelessWidget {
|
||||
// backgroundDecoration: BoxDecoration(color: theme.palette.background),
|
||||
// );
|
||||
return base64Text == null
|
||||
? Image.network(networkUrl)
|
||||
? Image.network(
|
||||
networkUrl,
|
||||
loadingBuilder: (_, child, p) {
|
||||
if (p == null) return child;
|
||||
// TODO: progress
|
||||
return Loading();
|
||||
},
|
||||
)
|
||||
: Image.memory(base64.decode(base64Text));
|
||||
case 'md':
|
||||
case 'markdown':
|
||||
|
@ -26,10 +26,10 @@ class ObjectTree extends StatelessWidget {
|
||||
|
||||
Widget _buildIcon(ObjectTreeItem item) {
|
||||
switch (item.type) {
|
||||
case 'blob': // github gql
|
||||
case 'blob': // github gql, gitlab
|
||||
case 'file': // github rest, gitea
|
||||
return SetiIcon(item.name, size: 36);
|
||||
case 'tree': // github gql
|
||||
case 'tree': // github gql, gitlab
|
||||
case 'dir': // github rest, gitea
|
||||
return Icon(
|
||||
Octicons.file_directory,
|
||||
|
Loading…
Reference in New Issue
Block a user