getImage method

Widget getImage({
  1. required BuildContext context,
  2. required String imagePath,
  3. required double height,
  4. required double width,
  5. required BoxFit fit,
})

Returns a widget to display the state's image with interactive zoom functionality.

  • context: The build context for rendering the dialog.
  • imagePath: The path or URL of the image to display.
  • height: The height of the image widget.
  • width: The width of the image widget.
  • fit: The box-fit behavior for the image.
  • Returns: A GestureDetector that displays the image and supports zoom functionality.

Implementation

Widget getImage({
  required BuildContext context,
  required String imagePath,
  required double height,
  required double width,
  required BoxFit fit,
}) {
  return GestureDetector(
    onTap: () {
      showDialog(
        context: context,
        builder: (context) => Dialog(
          child: InteractiveViewer(
            maxScale: 4.0,
            child: imagePath.startsWith('http')
                ? Image.network(
                    imagePath,
                    fit: BoxFit.contain,
                  )
                : Image.asset(
                    imagePath,
                    fit: BoxFit.contain,
                  ),
          ),
        ),
      );
    },
    child: imagePath.startsWith('http')
        ? Image.network(
            imagePath,
            height: height,
            width: width,
            fit: fit,
          )
        : Image.asset(
            imagePath,
            height: height,
            width: width,
            fit: fit,
          ),
  );
}