mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 08:04:51 +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['name'].first,
|
||||||
params['ref'].first,
|
params['ref'].first,
|
||||||
path: params['path']?.first,
|
path: params['path']?.first,
|
||||||
|
raw: params['raw']?.first,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -24,7 +25,8 @@ class ObjectScreen extends StatelessWidget {
|
|||||||
final String name;
|
final String name;
|
||||||
final String ref;
|
final String ref;
|
||||||
final String path;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -32,6 +34,12 @@ class ObjectScreen extends StatelessWidget {
|
|||||||
// canRefresh: !_isImage, // TODO:
|
// canRefresh: !_isImage, // TODO:
|
||||||
title: AppBarTitle(path == null ? 'Files' : path),
|
title: AppBarTitle(path == null ? 'Files' : path),
|
||||||
fetchData: () async {
|
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 suffix = path == null ? '' : '/$path';
|
||||||
final res = await Provider.of<AuthModel>(context)
|
final res = await Provider.of<AuthModel>(context)
|
||||||
.getWithCredentials('/repos/$owner/$name/contents$suffix?ref=$ref');
|
.getWithCredentials('/repos/$owner/$name/contents$suffix?ref=$ref');
|
||||||
@ -54,10 +62,17 @@ class ObjectScreen extends StatelessWidget {
|
|||||||
return ObjectTree(
|
return ObjectTree(
|
||||||
items: items.map((v) {
|
items: items.map((v) {
|
||||||
// if (item.type == 'commit') return null;
|
// 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(
|
return ObjectTreeItem(
|
||||||
name: v.name,
|
name: v.name,
|
||||||
type: v.type,
|
type: v.type,
|
||||||
url: '/$owner/$name/blob/$ref?path=${v.path.urlencode}',
|
url: uri.toString(),
|
||||||
downloadUrl: v.downloadUrl,
|
downloadUrl: v.downloadUrl,
|
||||||
size: v.type == 'file' ? v.size : null,
|
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:flutter_highlight/theme_map.dart';
|
||||||
import 'package:git_touch/models/code.dart';
|
import 'package:git_touch/models/code.dart';
|
||||||
import 'package:git_touch/models/theme.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:git_touch/widgets/markdown_view.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_highlight/flutter_highlight.dart';
|
import 'package:flutter_highlight/flutter_highlight.dart';
|
||||||
@ -38,7 +39,14 @@ class BlobView extends StatelessWidget {
|
|||||||
// backgroundDecoration: BoxDecoration(color: theme.palette.background),
|
// backgroundDecoration: BoxDecoration(color: theme.palette.background),
|
||||||
// );
|
// );
|
||||||
return base64Text == null
|
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));
|
: Image.memory(base64.decode(base64Text));
|
||||||
case 'md':
|
case 'md':
|
||||||
case 'markdown':
|
case 'markdown':
|
||||||
|
@ -26,10 +26,10 @@ class ObjectTree extends StatelessWidget {
|
|||||||
|
|
||||||
Widget _buildIcon(ObjectTreeItem item) {
|
Widget _buildIcon(ObjectTreeItem item) {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 'blob': // github gql
|
case 'blob': // github gql, gitlab
|
||||||
case 'file': // github rest, gitea
|
case 'file': // github rest, gitea
|
||||||
return SetiIcon(item.name, size: 36);
|
return SetiIcon(item.name, size: 36);
|
||||||
case 'tree': // github gql
|
case 'tree': // github gql, gitlab
|
||||||
case 'dir': // github rest, gitea
|
case 'dir': // github rest, gitea
|
||||||
return Icon(
|
return Icon(
|
||||||
Octicons.file_directory,
|
Octicons.file_directory,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user