1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-30 00:36:28 +00:00
comunicmobile/lib/ui/widgets/network_image_widget.dart

70 lines
1.8 KiB
Dart
Raw Normal View History

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;
final bool allowFullScreen;
2019-05-11 07:48:01 +00:00
final bool roundedEdges;
2019-05-11 07:43:30 +00:00
final double width;
final double height;
const NetworkImageWidget({
Key key,
@required this.url,
this.allowFullScreen = false,
this.width,
this.height,
2019-05-11 07:48:01 +00:00
this.roundedEdges = true,
2019-05-11 07:43:30 +00:00
}) : assert(url != null),
assert(allowFullScreen != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Material(
child: InkWell(
onTap: allowFullScreen
? () {
showImageFullScreen(context, url);
}
: null,
child: CachedNetworkImage(
imageUrl: url,
width: width,
height: height,
fit: BoxFit.cover,
placeholder: (c, s) => Container(
width: width,
height: height,
color: Colors.lightBlueAccent,
child: Center(
child: CircularProgressIndicator(),
),
),
errorWidget: (c, s, o) => Container(
width: width,
height: height,
color: Colors.red,
child: Center(
child: Icon(
Icons.error,
color: Colors.white,
),
),
),
),
),
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,
);
}
}