2022-12-25 12:30:20 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../models/config.dart';
|
|
|
|
import '../models/mode.dart';
|
|
|
|
import '/models/media_file.dart';
|
|
|
|
import 'package:photo_gallery/photo_gallery.dart';
|
|
|
|
import 'package:transparent_image/transparent_image.dart';
|
|
|
|
|
2022-12-29 12:12:06 +03:00
|
|
|
class ThumbnailMediaFile extends StatelessWidget {
|
2022-12-25 12:30:20 +03:00
|
|
|
final MediaFile file;
|
|
|
|
final Color failIconColor;
|
2022-12-29 08:45:28 +03:00
|
|
|
final Config config;
|
2022-12-29 12:12:06 +03:00
|
|
|
const ThumbnailMediaFile({super.key, required this.file, required this.failIconColor,required this.config});
|
2022-12-25 12:30:20 +03:00
|
|
|
|
|
|
|
Color adjustFailedBgColor() {
|
|
|
|
if (config.mode == Mode.dark) {
|
|
|
|
return lighten(
|
|
|
|
config.backgroundColor,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return darken(config.backgroundColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Color darken(Color color, [double amount = .03]) {
|
|
|
|
assert(amount >= 0 && amount <= 1);
|
|
|
|
final hsl = HSLColor.fromColor(color);
|
|
|
|
final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0));
|
|
|
|
return hslDark.toColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
Color lighten(Color color, [double amount = .05]) {
|
|
|
|
assert(amount >= 0 && amount <= 1);
|
|
|
|
final hsl = HSLColor.fromColor(color);
|
|
|
|
final hslLight =
|
|
|
|
hsl.withLightness((hsl.lightness + amount).clamp(0.0, 1.0));
|
|
|
|
return hslLight.toColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder(
|
|
|
|
future: file.thumbnail == null ? file.getThumbnail() : null,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Stack(
|
|
|
|
fit: StackFit.passthrough,
|
|
|
|
children: [
|
|
|
|
if (file.thumbnailFailed)
|
|
|
|
Container(
|
|
|
|
color: adjustFailedBgColor(),
|
|
|
|
child: Icon(
|
|
|
|
file.type == MediumType.image
|
|
|
|
? Icons.image_not_supported
|
|
|
|
: Icons.videocam_off_rounded,
|
|
|
|
size: 50,
|
|
|
|
color: failIconColor,
|
|
|
|
))
|
|
|
|
else if (file.thumbnail != null)
|
|
|
|
Hero(
|
2022-12-29 08:45:28 +03:00
|
|
|
tag: file.medium.id,
|
2022-12-25 12:30:20 +03:00
|
|
|
child: FadeInImage(
|
|
|
|
fadeInDuration: const Duration(milliseconds: 200),
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
placeholder: MemoryImage(kTransparentImage),
|
|
|
|
image: MemoryImage(file.thumbnail!),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
else
|
|
|
|
const SizedBox(),
|
|
|
|
if (file.thumbnail != null && !file.thumbnailFailed)
|
|
|
|
Positioned(
|
|
|
|
bottom: 10,
|
|
|
|
left: 10,
|
|
|
|
child: Icon(
|
2022-12-29 08:45:28 +03:00
|
|
|
file.medium.mediumType == MediumType.video
|
2022-12-25 12:30:20 +03:00
|
|
|
? Icons.video_camera_back
|
|
|
|
: null,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 20,
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|