2022-12-29 08:45:28 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '/models/media_file.dart';
|
|
|
|
import 'package:transparent_image/transparent_image.dart';
|
|
|
|
|
|
|
|
class ThumbnailMedia extends StatelessWidget {
|
|
|
|
final MediaFile media;
|
|
|
|
final bool noIcon;
|
2023-01-20 09:58:21 +03:00
|
|
|
final double? width, height;
|
|
|
|
final Color? backgroundColor;
|
|
|
|
final BoxFit fit;
|
|
|
|
final bool highQuality;
|
|
|
|
final double radius, borderWidth;
|
|
|
|
final Color borderColor;
|
2022-12-30 05:18:18 +03:00
|
|
|
final Widget Function(MediaFile media, BuildContext context)? onErrorBuilder;
|
|
|
|
const ThumbnailMedia(
|
|
|
|
{super.key,
|
|
|
|
required this.media,
|
2023-01-20 09:58:21 +03:00
|
|
|
this.fit = BoxFit.cover,
|
2022-12-30 05:18:18 +03:00
|
|
|
this.onErrorBuilder,
|
2023-01-20 09:58:21 +03:00
|
|
|
this.radius = 0,
|
|
|
|
this.highQuality = true,
|
|
|
|
this.borderColor = Colors.transparent,
|
|
|
|
this.borderWidth = 0,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
this.backgroundColor,
|
2022-12-30 05:18:18 +03:00
|
|
|
this.noIcon = false});
|
2022-12-29 08:45:28 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder(
|
2023-01-20 09:58:21 +03:00
|
|
|
future: media.thumbnail == null
|
|
|
|
? media.getThumbnail(highQuality: highQuality)
|
|
|
|
: null,
|
2022-12-29 08:45:28 +03:00
|
|
|
builder: (context, snapshot) {
|
2023-01-20 09:58:21 +03:00
|
|
|
return Container(
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: backgroundColor,
|
|
|
|
borderRadius: BorderRadius.circular(radius),
|
|
|
|
border: Border.all(color: borderColor, width: borderWidth)),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(radius),
|
|
|
|
child: Stack(
|
|
|
|
fit: StackFit.passthrough,
|
|
|
|
children: [
|
|
|
|
if (snapshot.hasError && onErrorBuilder == null)
|
|
|
|
Center(
|
|
|
|
child: Icon(
|
|
|
|
media.isImage
|
|
|
|
? Icons.image_not_supported
|
|
|
|
: Icons.videocam_off_rounded,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
else if (snapshot.hasError && onErrorBuilder == null)
|
|
|
|
onErrorBuilder!(media, context)
|
|
|
|
else if (media.thumbnail != null)
|
|
|
|
FadeInImage(
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
fadeInDuration: const Duration(milliseconds: 200),
|
|
|
|
fit: fit,
|
|
|
|
placeholder: MemoryImage(kTransparentImage),
|
|
|
|
image: MemoryImage(media.thumbnail!),
|
|
|
|
)
|
|
|
|
else
|
|
|
|
SizedBox(
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
),
|
|
|
|
if (media.thumbnail != null && !noIcon)
|
|
|
|
Positioned(
|
|
|
|
bottom: 10,
|
|
|
|
left: 10,
|
|
|
|
child: Icon(
|
|
|
|
media.isVideo ? Icons.video_camera_back : null,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 20,
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-12-29 08:45:28 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|