when<T> method
T?
when<T>({
- T nv21(
- Nv21Image image
- T bgra8888(
- Bgra8888Image image
- T jpeg(
- JpegImage image
- T yuv420(
- Yuv420Image image
Helper function to decide what to do depending on the AnalysisImage format with type safe checks.
Implementation
T? when<T>({
T Function(Nv21Image image)? nv21,
T Function(Bgra8888Image image)? bgra8888,
T Function(JpegImage image)? jpeg,
T Function(Yuv420Image image)? yuv420,
}) {
if (this is Nv21Image) {
return nv21?.call(this as Nv21Image);
} else if (this is Bgra8888Image) {
return bgra8888?.call(this as Bgra8888Image);
} else if (this is JpegImage) {
return jpeg?.call(this as JpegImage);
} else if (this is Yuv420Image) {
return yuv420?.call(this as Yuv420Image);
} else {
throw "Unsupported AnalysisImage format: $format";
}
}