TKeyValue.image constructor

TKeyValue.image(
  1. String key,
  2. String? url, {
  3. Uint8List? bytes,
  4. double size = 40.0,
  5. double? imageWidth,
  6. double? imageHeight,
  7. BoxFit fit = BoxFit.cover,
  8. BorderRadius? borderRadius,
  9. bool forceCache = false,
  10. Widget? icon,
  11. double? width,
  12. Alignment? alignment,
  13. double? minWidth,
  14. double? maxWidth,
})

Creates a key-value item for displaying an image using TImage.

Implementation

factory TKeyValue.image(
  String key,
  String? url, {
  Uint8List? bytes,
  double size = 40.0,
  double? imageWidth,
  double? imageHeight,
  BoxFit fit = BoxFit.cover,
  BorderRadius? borderRadius,
  bool forceCache = false,
  Widget? icon,
  double? width,
  Alignment? alignment,
  double? minWidth,
  double? maxWidth,
}) {
  Widget? widget;
  final hasUrl = url != null && url.isNotEmpty;
  final hasBytes = bytes != null && bytes.isNotEmpty;
  if (hasUrl || hasBytes) {
    widget = TImage(
      url: url,
      bytes: bytes,
      size: (imageWidth == null && imageHeight == null) ? size : null,
      width: imageWidth,
      height: imageHeight,
      fit: fit,
      border: borderRadius != null
          ? RoundedRectangleBorder(borderRadius: borderRadius)
          : const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(6))),
      forceCache: forceCache,
    );
  }
  return TKeyValue(
    key,
    value: widget == null ? (url ?? '') : null,
    widget: widget,
    icon: icon,
    width: width,
    alignment: alignment,
    minWidth: minWidth,
    maxWidth: maxWidth,
  );
}