MusicPlayer/lib/ui/cover_image.dart

52 lines
1.4 KiB
Dart

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;
final Icon? icon;
final Color? backgroundColor;
const CoverImage({
Key? key,
required this.music,
this.width,
this.height,
this.icon,
this.fit,
this.backgroundColor,
}) : 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,
progressIndicatorBuilder: (c, s, p) => _loadingWidget(p.progress),
fit: fit,
errorWidget: (c, s, e) => _loadingWidget(null),
);
}
Widget _loadingWidget(double? progress) => Container(
color: backgroundColor ?? Colors.black,
width: width,
height: height,
child: Center(
child: progress == null
? icon
: CircularProgressIndicator(value: progress),
),
);
}