1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-18 19:22:54 +01:00
git-touch-android-ios-app/lib/widgets/blob_view.dart

75 lines
2.4 KiB
Dart
Raw Normal View History

2020-01-30 07:06:25 +01:00
import 'dart:convert';
2019-12-11 16:58:25 +01:00
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';
2019-12-11 16:58:25 +01:00
import 'package:git_touch/widgets/markdown_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_highlight/flutter_highlight.dart';
import 'package:photo_view/photo_view.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/utils/utils.dart';
class BlobView extends StatelessWidget {
2020-01-30 07:06:25 +01:00
final String name;
2020-01-31 07:31:24 +01:00
// final String text;
2020-01-30 07:06:25 +01:00
final String base64Text;
final String networkUrl;
2020-01-31 07:31:24 +01:00
BlobView(
this.name, {
// this.text,
@required this.base64Text,
this.networkUrl,
});
2019-12-11 16:58:25 +01:00
@override
Widget build(BuildContext context) {
final codeProvider = Provider.of<CodeModel>(context);
final theme = Provider.of<ThemeModel>(context);
2020-01-31 07:54:46 +01:00
switch (name.ext) {
2019-12-11 16:58:25 +01:00
// TODO: All image types
case 'png':
case 'jpg':
case 'jpeg':
case 'gif':
case 'webp':
2020-01-30 07:06:25 +01:00
// return PhotoView(
// imageProvider: MemoryImage(Uint8List.fromList(bits)),
// backgroundDecoration: BoxDecoration(color: theme.palette.background),
// );
return base64Text == null
? Image.network(
networkUrl,
loadingBuilder: (_, child, p) {
if (p == null) return child;
// TODO: progress
return Loading();
},
)
2020-01-30 07:06:25 +01:00
: Image.memory(base64.decode(base64Text));
2019-12-11 16:58:25 +01:00
case 'md':
case 'markdown':
return Padding(
padding: CommonStyle.padding,
2020-01-31 07:31:24 +01:00
child: MarkdownView(base64Text.base64ToUtf8), // TODO: basePath
2019-12-11 16:58:25 +01:00
);
default:
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: HighlightView(
2020-01-31 07:31:24 +01:00
base64Text.base64ToUtf8,
2020-01-31 09:40:20 +01:00
language: name.ext ?? 'plaintext',
theme: themeMap[theme.brightness == Brightness.dark
? codeProvider.themeDark
: codeProvider.theme],
2019-12-11 16:58:25 +01:00
padding: CommonStyle.padding,
textStyle: TextStyle(
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: codeProvider.fontFamilyUsed),
),
);
}
}
}