imageWidget static method
Widget
imageWidget({
- required String labelText,
- required dynamic image,
- required String? remark,
- required String noImage,
- dynamic cameraOnTap()?,
- dynamic galleryOnTap()?,
- String? validator()?,
- AutovalidateMode? autovalidateMode,
- required Size screenSize,
- bool hideCamera = true,
- bool isMandatory = false,
- bool deleteIcon = false,
- dynamic delImgOnPressed()?,
Implementation
static Widget imageWidget(
{required String labelText,
required dynamic image,
required String? remark,
required String noImage,
dynamic Function()? cameraOnTap,
dynamic Function()? galleryOnTap,
String? Function(String?)? validator,
AutovalidateMode? autovalidateMode,
required Size screenSize,
bool hideCamera = true,
bool isMandatory = false,
bool deleteIcon = false,
dynamic Function()? delImgOnPressed}) {
return batchWidget(
remark: remark,
widget: FormField(
validator: validator,
builder: (field) => Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(width: 1.0, color: Colors.black45),
borderRadius: const BorderRadius.all(Radius.circular(10.0)),
),
child: Column(
children: [
const SizedBox(
height: 10.0,
),
Text(
isMandatory ? '$labelText *' : labelText,
style: TextStyle(
color: Colors.blueGrey,
fontSize: screenSize.width * 0.04,
fontWeight: FontWeight.w500),
),
Container(
height: Get.height / 2.8,
margin: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: Colors.blue.shade50,
borderRadius:
const BorderRadius.all(Radius.circular(10.0)),
),
child: Center(
child: image != null && image != ''
? InteractiveViewer(
minScale: 0.5,
maxScale: 4,
child:
kIsWeb?Image.network(
image,
gaplessPlayback: true,
errorBuilder: (context, error, stackTrace) =>
const Padding(
padding: EdgeInsets.only(
top: 10.0,
bottom: 20.0,
),
child: Text(
'Image is corrupted',
style: TextStyle(
fontSize: 12.0, color: Colors.grey),
),
),
):
isBase64(image)?Image.memory(
base64.decode(image),
gaplessPlayback: true,
errorBuilder: (context, error, stackTrace) =>
const Padding(
padding: EdgeInsets.only(
top: 10.0,
bottom: 20.0,
),
child: Text(
'Image is corrupted',
style: TextStyle(
fontSize: 12.0, color: Colors.grey),
),
),
):
Image.file(
File(image),
gaplessPlayback: true,
errorBuilder: (context, error, stackTrace) =>
const Padding(
padding: EdgeInsets.only(
top: 10.0,
bottom: 20.0,
),
child: Text(
'Image is corrupted',
style: TextStyle(
fontSize: 12.0, color: Colors.grey),
),
),
))
: Text(
noImage,
style: TextStyle(
color: Colors.grey.shade500,
fontSize: screenSize.width * 0.035,
),
),
),
),
if (hideCamera == false)
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
subImageWidget(
icon: Icons.camera,
onTap: cameraOnTap,
text: 'Camera'),
subImageWidget(
icon: Icons.image,
onTap: galleryOnTap,
text: 'Gallery'),
if (deleteIcon)
subImageWidget(
icon: Icons.delete,
onTap: delImgOnPressed,
text: 'Delete',
redClr: true),
],
),
],
),
),
if (field.errorText != null)
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
"${field.errorText}",
style: TextStyle(
color: Colors.red, fontSize: screenSize.width * 0.030),
),
),
const SizedBox(
height: 10.0,
),
],
),
),
);
}