This repository has been archived on 2024-10-18. You can view files and clone it, but cannot push or open issues or pull requests.
ftc_patient_app/lib/view/custom_widgets/custom_image_widgets.dart

105 lines
2.4 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
class CustomImageWidget extends StatelessWidget {
final String imagePath;
final BoxFit? fit;
final double? width;
final double? height;
final Color? imageColor;
const CustomImageWidget({
Key? key,
this.imagePath = "",
this.fit,
this.width,
this.height,
this.imageColor,
}) : super(key: key);
@override
Widget build(BuildContext context) {
if (imagePath.startsWith("http")) {
// handel network image here.
return Image.network(
imagePath,
fit: fit,
height: height,
width: width,
color: imageColor,
errorBuilder: (ctx, obj, stc) {
return _ErrorWidget(
size: height ?? 50.0,
color: imageColor,
);
},
);
} else if (imagePath.trim().isEmpty) {
return _ErrorWidget(
size: height ?? 50.0,
color: imageColor,
);
} else if (imagePath.startsWith("assets/") && imagePath.endsWith(".png")) {
return Image.asset(
imagePath,
fit: fit,
height: height,
width: width,
color: imageColor,
errorBuilder: (ctx, obj, stc) {
return _ErrorWidget(
size: height ?? 50.0,
color: imageColor,
);
},
);
} else if(imagePath.startsWith("assets/") && imagePath.endsWith(".svg")) {
return SvgPicture.asset(
imagePath,
height: height,
width: width,
colorFilter: imageColor!=null? ColorFilter.mode(imageColor!, BlendMode.srcIn):null,
// color: imageColor,
);
}
return Image.file(
File(imagePath),
fit: fit,
height: height,
width: width,
errorBuilder: (ctx, obj, stc) {
return _ErrorWidget(
size: height ?? 50.0,
color: imageColor,
);
},
);
}
}
class _ErrorWidget extends StatelessWidget {
final double size;
final Color? color;
const _ErrorWidget({
Key? key,
this.size = 50.0,
this.color,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.center,
child: Icon(
Icons.error_outline,
size: size,
color: color ?? CustomAppColors.kIconColor,
),
);
}
}