2022-03-23 20:15:29 +00:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:music_web_player/api.dart';
|
|
|
|
import 'package:music_web_player/config.dart';
|
|
|
|
|
|
|
|
class CoverImage extends StatelessWidget {
|
|
|
|
final MusicEntry music;
|
|
|
|
final double? width;
|
|
|
|
final double? height;
|
|
|
|
final BoxFit? fit;
|
2022-03-23 20:27:05 +00:00
|
|
|
final Icon? icon;
|
2022-03-24 08:20:43 +00:00
|
|
|
final Color? backgroundColor;
|
2022-03-23 20:15:29 +00:00
|
|
|
|
|
|
|
const CoverImage({
|
|
|
|
Key? key,
|
|
|
|
required this.music,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
2022-03-23 20:27:05 +00:00
|
|
|
this.icon,
|
2022-03-23 20:15:29 +00:00
|
|
|
this.fit,
|
2022-03-24 08:20:43 +00:00
|
|
|
this.backgroundColor,
|
2022-03-23 20:15:29 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return CachedNetworkImage(
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
|
|
|
imageUrl: music.coverURL,
|
|
|
|
cacheKey: music.coverCacheKey,
|
|
|
|
httpHeaders: {"Token": config.apiToken},
|
|
|
|
useOldImageOnUrlChange: false,
|
2022-03-23 20:27:05 +00:00
|
|
|
progressIndicatorBuilder: (c, s, p) => _loadingWidget(p.progress),
|
2022-03-23 20:15:29 +00:00
|
|
|
fit: fit,
|
2022-03-23 20:27:05 +00:00
|
|
|
errorWidget: (c, s, e) => _loadingWidget(null),
|
2022-03-23 20:15:29 +00:00
|
|
|
);
|
|
|
|
}
|
2022-03-23 20:27:05 +00:00
|
|
|
|
|
|
|
Widget _loadingWidget(double? progress) => Container(
|
2022-03-24 08:20:43 +00:00
|
|
|
color: backgroundColor ?? Colors.black,
|
2022-03-23 20:27:05 +00:00
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
child: Center(
|
|
|
|
child: progress == null
|
|
|
|
? icon
|
|
|
|
: CircularProgressIndicator(value: progress),
|
|
|
|
),
|
|
|
|
);
|
2022-03-23 20:15:29 +00:00
|
|
|
}
|