2022-12-29 08:45:28 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-20 09:58:21 +03:00
|
|
|
import 'package:transparent_image/transparent_image.dart';
|
2022-12-29 08:45:28 +03:00
|
|
|
import '../models/media_file.dart';
|
|
|
|
|
2023-01-20 09:58:21 +03:00
|
|
|
class PhotoProvider extends StatelessWidget {
|
2022-12-29 08:45:28 +03:00
|
|
|
final MediaFile media;
|
|
|
|
final BoxFit fit;
|
|
|
|
final double? width, height;
|
2023-01-20 09:58:21 +03:00
|
|
|
final Color? backgroundColor;
|
|
|
|
final Widget Function(BuildContext context)? onFailBuilder;
|
2022-12-29 08:45:28 +03:00
|
|
|
|
|
|
|
const PhotoProvider({
|
|
|
|
super.key,
|
|
|
|
required this.media,
|
2023-01-20 09:58:21 +03:00
|
|
|
this.onFailBuilder,
|
2022-12-29 08:45:28 +03:00
|
|
|
this.fit = BoxFit.contain,
|
2023-01-20 09:58:21 +03:00
|
|
|
this.backgroundColor,
|
2022-12-29 08:45:28 +03:00
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-01-20 09:58:21 +03:00
|
|
|
return FutureBuilder(
|
|
|
|
future: media.getData(),
|
|
|
|
builder: ((context, snapshot) {
|
|
|
|
return Container(
|
|
|
|
color: backgroundColor,
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
child: (snapshot.hasError && onFailBuilder != null)
|
|
|
|
? onFailBuilder!(context)
|
|
|
|
: (snapshot.hasData)
|
|
|
|
? FadeInImage(
|
|
|
|
fadeInDuration: const Duration(milliseconds: 200),
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
placeholder: MemoryImage(kTransparentImage),
|
|
|
|
image: MemoryImage(snapshot.data!),
|
|
|
|
)
|
|
|
|
: const SizedBox(),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
2022-12-29 08:45:28 +03:00
|
|
|
}
|
|
|
|
}
|