mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 08:04:51 +01:00
refactor: using string extension
This commit is contained in:
parent
05a4ffeeb8
commit
db92210659
@ -36,7 +36,7 @@ class GiteaRepoScreen extends StatelessWidget {
|
||||
]);
|
||||
return Tuple2(
|
||||
GiteaRepository.fromJson(res[0]),
|
||||
convertBase64ToString(res[1]['content']),
|
||||
(res[1]['content'] as String)?.base64ToUtf8,
|
||||
);
|
||||
},
|
||||
bodyBuilder: (t, setState) {
|
||||
|
@ -88,7 +88,7 @@ class ObjectScreen extends StatelessWidget {
|
||||
final v = GithubTreeItem.fromJson(data);
|
||||
return BlobView(
|
||||
path,
|
||||
base64Text: v.content,
|
||||
base64Text: v.content?.dropLineBreak,
|
||||
networkUrl: v.downloadUrl,
|
||||
);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class RepositoryScreen extends StatelessWidget {
|
||||
Future<String> _fetchReadme(BuildContext context) async {
|
||||
final data = await Provider.of<AuthModel>(context)
|
||||
.getWithCredentials('/repos/$owner/$name/readme');
|
||||
return convertBase64ToString(data['content']);
|
||||
return (data['content'] as String)?.dropLineBreak?.base64ToUtf8;
|
||||
}
|
||||
|
||||
Widget _buildLanguages(BuildContext context, GhRepoRepository repo) {
|
||||
|
@ -1,13 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
extension MyString<T extends String> on String {
|
||||
int get toInt {
|
||||
return int.parse(this);
|
||||
}
|
||||
|
||||
String get urlencode {
|
||||
return Uri.encodeComponent(this);
|
||||
}
|
||||
|
||||
String get urldecode {
|
||||
return Uri.decodeComponent(this);
|
||||
}
|
||||
int get toInt => int.parse(this);
|
||||
String get urlencode => Uri.encodeComponent(this);
|
||||
String get urldecode => Uri.decodeComponent(this);
|
||||
String get dropLineBreak => this.replaceAll('\n', '');
|
||||
String get base64ToUtf8 => utf8.decode(base64.decode(this));
|
||||
}
|
||||
|
@ -189,12 +189,6 @@ class RouterScreen {
|
||||
|
||||
final dateFormat = DateFormat.yMMMMd();
|
||||
|
||||
String convertBase64ToString(String input) {
|
||||
if (input == null) return null;
|
||||
final bits = base64.decode(input.replaceAll('\n', ''));
|
||||
return utf8.decode(bits);
|
||||
}
|
||||
|
||||
int sortByKey<T>(T key, T a, T b) {
|
||||
if (a == key && b != key) return -1;
|
||||
if (a != key && b == key) return 1;
|
||||
|
@ -14,11 +14,15 @@ import 'package:git_touch/utils/utils.dart';
|
||||
|
||||
class BlobView extends StatelessWidget {
|
||||
final String name;
|
||||
final String text;
|
||||
// final String text;
|
||||
final String base64Text;
|
||||
final String networkUrl;
|
||||
BlobView(this.name, {this.text, this.base64Text, this.networkUrl})
|
||||
: assert(text == null || base64Text == null);
|
||||
BlobView(
|
||||
this.name, {
|
||||
// this.text,
|
||||
@required this.base64Text,
|
||||
this.networkUrl,
|
||||
});
|
||||
|
||||
String get _extname {
|
||||
var dotext = p.extension(name);
|
||||
@ -27,7 +31,6 @@ class BlobView extends StatelessWidget {
|
||||
}
|
||||
|
||||
String get _language => _extname.isEmpty ? 'plaintext' : _extname;
|
||||
String get _text => text ?? utf8.decode(base64.decode(base64Text));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -55,13 +58,13 @@ class BlobView extends StatelessWidget {
|
||||
case 'markdown':
|
||||
return Padding(
|
||||
padding: CommonStyle.padding,
|
||||
child: MarkdownView(_text), // TODO: basePath
|
||||
child: MarkdownView(base64Text.base64ToUtf8), // TODO: basePath
|
||||
);
|
||||
default:
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: HighlightView(
|
||||
_text,
|
||||
base64Text.base64ToUtf8,
|
||||
language: _language,
|
||||
theme: themeMap[theme.brightness == Brightness.dark
|
||||
? codeProvider.themeDark
|
||||
|
Loading…
x
Reference in New Issue
Block a user