mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00

Downloaded tracks are saved with metadata. Only MP3 file metadata support is available in local track player for now
99 lines
2.6 KiB
Dart
99 lines
2.6 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
class UniversalImage extends HookWidget {
|
|
final String path;
|
|
final double? height;
|
|
final double? width;
|
|
final double scale;
|
|
final PlaceholderWidgetBuilder? placeholder;
|
|
const UniversalImage({
|
|
required this.path,
|
|
this.height,
|
|
this.width,
|
|
this.placeholder,
|
|
this.scale = 1,
|
|
Key? key,
|
|
}) : super(key: key);
|
|
|
|
static ImageProvider imageProvider(
|
|
String path, {
|
|
final double? height,
|
|
final double? width,
|
|
final double scale = 1,
|
|
}) {
|
|
if (path.startsWith("http")) {
|
|
return CachedNetworkImageProvider(
|
|
path,
|
|
maxHeight: height?.toInt(),
|
|
maxWidth: width?.toInt(),
|
|
cacheKey: path,
|
|
scale: scale,
|
|
);
|
|
} else if (Uri.tryParse(path) != null) {
|
|
return FileImage(File(path), scale: scale);
|
|
}
|
|
return MemoryImage(base64Decode(path), scale: scale);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (path.startsWith("http")) {
|
|
return CachedNetworkImage(
|
|
imageUrl: path,
|
|
height: height,
|
|
width: width,
|
|
maxWidthDiskCache: width?.toInt(),
|
|
maxHeightDiskCache: height?.toInt(),
|
|
memCacheHeight: height?.toInt(),
|
|
memCacheWidth: width?.toInt(),
|
|
placeholder: placeholder,
|
|
cacheKey: path,
|
|
);
|
|
} else if (Uri.tryParse(path) != null) {
|
|
return Image.file(
|
|
File(path),
|
|
width: width,
|
|
height: height,
|
|
cacheHeight: height?.toInt(),
|
|
cacheWidth: width?.toInt(),
|
|
scale: scale,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return placeholder?.call(context, error.toString()) ??
|
|
Image.asset(
|
|
"assets/placeholder.png",
|
|
width: width,
|
|
height: height,
|
|
cacheHeight: height?.toInt(),
|
|
cacheWidth: width?.toInt(),
|
|
scale: scale,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
return Image.memory(
|
|
base64Decode(path),
|
|
width: width,
|
|
height: height,
|
|
cacheHeight: height?.toInt(),
|
|
cacheWidth: width?.toInt(),
|
|
scale: scale,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return placeholder?.call(context, error.toString()) ??
|
|
Image.asset(
|
|
"assets/placeholder.png",
|
|
width: width,
|
|
height: height,
|
|
cacheHeight: height?.toInt(),
|
|
cacheWidth: width?.toInt(),
|
|
scale: scale,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|