2019-05-11 07:43:30 +00:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:comunic/utils/ui_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Network image widget
|
|
|
|
///
|
|
|
|
/// Widget useful to show remote image
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
|
|
|
class NetworkImageWidget extends StatelessWidget {
|
|
|
|
final String url;
|
2022-03-12 09:57:11 +00:00
|
|
|
final String? cacheKey;
|
2022-03-10 18:39:57 +00:00
|
|
|
final String? thumbnailURL;
|
2022-03-12 09:57:11 +00:00
|
|
|
final String? thumbnailCacheKey;
|
2019-05-11 07:43:30 +00:00
|
|
|
final bool allowFullScreen;
|
2019-05-11 07:48:01 +00:00
|
|
|
final bool roundedEdges;
|
2022-03-10 18:39:57 +00:00
|
|
|
final double? width;
|
|
|
|
final double? height;
|
|
|
|
final double? loadingHeight;
|
2019-05-11 07:43:30 +00:00
|
|
|
|
|
|
|
const NetworkImageWidget({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.url,
|
2022-03-12 09:57:11 +00:00
|
|
|
this.cacheKey,
|
2021-03-10 23:02:41 +00:00
|
|
|
this.thumbnailURL,
|
2022-03-12 09:57:11 +00:00
|
|
|
this.thumbnailCacheKey,
|
2019-05-11 07:43:30 +00:00
|
|
|
this.allowFullScreen = false,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
2019-05-11 07:48:01 +00:00
|
|
|
this.roundedEdges = true,
|
2019-05-20 07:13:12 +00:00
|
|
|
this.loadingHeight,
|
2022-03-12 09:57:11 +00:00
|
|
|
}) : super(key: key);
|
2019-05-11 07:43:30 +00:00
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
double? get _loadingHeight => loadingHeight != null ? loadingHeight : height;
|
2019-05-20 07:13:12 +00:00
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
double? get _loadingWidth => width;
|
2019-05-20 07:13:12 +00:00
|
|
|
|
2019-05-11 07:43:30 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Material(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: allowFullScreen
|
|
|
|
? () {
|
2022-03-12 09:57:11 +00:00
|
|
|
showImageFullScreen(context, url, cacheKey: cacheKey);
|
2019-05-11 07:43:30 +00:00
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: CachedNetworkImage(
|
2021-03-10 23:02:41 +00:00
|
|
|
imageUrl: thumbnailURL ?? url,
|
2022-03-12 09:57:11 +00:00
|
|
|
cacheKey: thumbnailURL != null ? thumbnailCacheKey : cacheKey,
|
2019-05-11 07:43:30 +00:00
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
placeholder: (c, s) => Container(
|
2022-03-12 09:57:11 +00:00
|
|
|
width: _loadingWidth,
|
|
|
|
height: _loadingHeight,
|
|
|
|
color: Colors.lightBlueAccent,
|
|
|
|
child: Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
),
|
2019-05-11 07:43:30 +00:00
|
|
|
errorWidget: (c, s, o) => Container(
|
2022-03-12 09:57:11 +00:00
|
|
|
width: _loadingWidth,
|
|
|
|
height: _loadingHeight,
|
|
|
|
color: Colors.red,
|
|
|
|
child: Center(
|
|
|
|
child: Icon(
|
|
|
|
Icons.error,
|
|
|
|
color: Colors.white,
|
2019-05-11 07:43:30 +00:00
|
|
|
),
|
2022-03-12 09:57:11 +00:00
|
|
|
),
|
|
|
|
),
|
2019-05-11 07:43:30 +00:00
|
|
|
),
|
|
|
|
),
|
2019-05-11 07:48:01 +00:00
|
|
|
borderRadius:
|
|
|
|
roundedEdges ? BorderRadius.all(Radius.circular(8.0)) : null,
|
2019-05-11 07:43:30 +00:00
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|