Skip to main content

LMFeedImage

LMFeedImage is a widget that displays an image within a feed post. It supports loading images from a URL or a local file. The widget provides customization options for styling the image, handling errors, and responding to tap events.


LMFeedImage

The LMFeedImage widget is part of the likeminds_feed_flutter_ui package. It is designed to be used within an LMFeedPostWidget to display images associated with a post.

Properties

  • imageUrl (String)

The URL of the image to be displayed. Either imageUrl or imageFile must be provided.

  • imageFile (File)

The local file representing the image to be displayed. Either imageUrl or imageFile must be provided.

  • onError (Function(String, StackTrace))

A callback function that is invoked when an error occurs while loading the image. It takes the error message and stack trace as parameters. This is an optional parameter.

  • style (LMFeedPostImageStyle)

The style configuration for the image. It allows customization of the image's appearance and behavior. This is an optional parameter.

  • onMediaTap (VoidCallback)

A callback function that is invoked when the image is tapped. This is an optional parameter.

Styling

The LMFeedPostImageStyle class allows you to customize the appearance and behavior of the LMFeedImage widget.

Customization variables

PropertyTypeDescriptionRequiredDefault
heightdoubleThe height of the image.
widthdoubleThe width of the image.
aspectRatiodoubleThe aspect ratio of the image.
borderRadiusBorderRadiusThe border radius of the image.
borderColorColorThe border color of the image.
loaderWidgetWidgetThe widget to be displayed while the image is loading.
errorWidgetWidgetThe widget to be displayed when an error occurs.
shimmerWidgetWidgetThe shimmer widget to be displayed while the image is loading.
boxFitBoxFitHow the image should be inscribed into the layout bounds.

You can create an instance of LMFeedPostImageStyle and pass it to the LMFeedImage widget to customize its appearance and behavior.

Usage Example

LMFeedImage(
imageUrl: 'https://example.com/image.jpg',
onError: (error, stackTrace) {
// Handle error
print('Error loading image: $error');
},
style: LMFeedPostImageStyle(
height: 200,
width: double.infinity,
borderRadius: BorderRadius.circular(8),
borderColor: Colors.grey,
loaderWidget: CircularProgressIndicator(),
errorWidget: Icon(Icons.error),
shimmerWidget: LMPostMediaShimmer(),
boxFit: BoxFit.cover,
),
onMediaTap: () {
// Handle image tap
print('Image tapped');
},
)

In this example, an LMFeedImage widget is created with the imageUrl property set to the URL of the image to be displayed. The onError callback is provided to handle any errors that occur while loading the image. The appearance and behavior of the image are customized using the LMFeedPostImageStyle class, specifying the height, width, border radius, border color, loader widget, error widget, shimmer widget, and box fit. The onMediaTap callback is used to handle taps on the image.