displayImageWithCloseButton function

Widget displayImageWithCloseButton(
  1. double width,
  2. double height,
  3. String path,
  4. dynamic onTap(),
  5. dynamic onDelete(), {
  6. String type = "network",
  7. BoxFit fit = BoxFit.contain,
  8. Uint8List? imageBytes,
})

Implementation

Widget displayImageWithCloseButton(double width, double height, String path, Function() onTap, Function() onDelete,
    {String type = "network", BoxFit fit = BoxFit.contain, Uint8List? imageBytes}){
  return InkWell(
      onTap: (){
        onTap();
      },
      child: Container(
          width: width,
          height: height,
          child: Stack(
            children: [
              if (type == "network")
                Image.network(path, fit: fit, errorBuilder: (
                    BuildContext context,
                    Object error,
                    StackTrace? stackTrace,
                    ){
                  return Container(child: Image.asset("assets/noimage.png"));
                }),
              if (type == "memory" && imageBytes != null)
                Image.memory(imageBytes, fit: BoxFit.contain,),
              Container(
                margin: EdgeInsets.only(right: width/10, left: width/10),
                alignment: Alignment.topRight,
                child: IconButton(icon: Icon(Icons.cancel, color: Colors.red,),
                    onPressed: onDelete),
              )
            ],
          ))
  );
}