mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-29 16:26:27 +00:00
78 lines
2.0 KiB
Dart
78 lines
2.0 KiB
Dart
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;
|
|
final String thumbnailURL;
|
|
final bool allowFullScreen;
|
|
final bool roundedEdges;
|
|
final double width;
|
|
final double height;
|
|
final double loadingHeight;
|
|
|
|
const NetworkImageWidget({
|
|
Key key,
|
|
@required this.url,
|
|
this.thumbnailURL,
|
|
this.allowFullScreen = false,
|
|
this.width,
|
|
this.height,
|
|
this.roundedEdges = true,
|
|
this.loadingHeight,
|
|
}) : assert(url != null),
|
|
assert(allowFullScreen != null),
|
|
super(key: key);
|
|
|
|
double get _loadingHeight => loadingHeight != null ? loadingHeight : height;
|
|
|
|
double get _loadingWidth => width;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Material(
|
|
child: InkWell(
|
|
onTap: allowFullScreen
|
|
? () {
|
|
showImageFullScreen(context, url);
|
|
}
|
|
: null,
|
|
child: CachedNetworkImage(
|
|
imageUrl: thumbnailURL ?? url,
|
|
width: width,
|
|
height: height,
|
|
fit: BoxFit.cover,
|
|
placeholder: (c, s) => Container(
|
|
width: _loadingWidth,
|
|
height: _loadingHeight,
|
|
color: Colors.lightBlueAccent,
|
|
child: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
),
|
|
errorWidget: (c, s, o) => Container(
|
|
width: _loadingWidth,
|
|
height: _loadingHeight,
|
|
color: Colors.red,
|
|
child: Center(
|
|
child: Icon(
|
|
Icons.error,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
borderRadius:
|
|
roundedEdges ? BorderRadius.all(Radius.circular(8.0)) : null,
|
|
clipBehavior: Clip.hardEdge,
|
|
);
|
|
}
|
|
}
|