Skip to content

Commit 7dddfff

Browse files
committed
fix: image caching issue
1 parent 891267c commit 7dddfff

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/blue_forms/widgets/form_input_images.dart

+21-4
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,20 @@ class _FormInputImagesWidgetSingleState extends State<_FormInputImagesWidgetSing
429429
final ImagePicker _picker = ImagePicker();
430430
bool _isLoading = false;
431431
String? _internalError;
432+
ImageProvider? _imageProvider;
433+
434+
@override
435+
void initState()
436+
{
437+
img.Image? image = widget.currentSavedValue ?? widget.definition.initialValue;
438+
439+
if (image != null)
440+
{
441+
_imageProvider = image.toImageProvider();
442+
}
443+
444+
super.initState();
445+
}
432446

433447
@override
434448
Widget build(BuildContext context)
@@ -518,9 +532,7 @@ class _FormInputImagesWidgetSingleState extends State<_FormInputImagesWidgetSing
518532

519533
Widget _buildPreview(BuildContext context, FormFieldState<img.Image?> state)
520534
{
521-
img.Image? image = state.value;
522-
523-
if (image == null)
535+
if (_imageProvider == null)
524536
{
525537
return Container(
526538
margin: context.paddingL,
@@ -556,7 +568,7 @@ class _FormInputImagesWidgetSingleState extends State<_FormInputImagesWidgetSing
556568
margin: context.paddingL,
557569
child: ArchImage(
558570
edgePreset: kImageEdgePreset.outerShadowM,
559-
image: image.toImageProvider(),
571+
image: _imageProvider!,
560572
),
561573
),
562574
Padding(
@@ -632,6 +644,7 @@ class _FormInputImagesWidgetSingleState extends State<_FormInputImagesWidgetSing
632644
{
633645
state.didChange(image);
634646
widget.definition.onChange?.call([image!]);
647+
_imageProvider = image!.toImageProvider();
635648
});
636649
}
637650
finally
@@ -662,6 +675,9 @@ class _FormInputImagesWidgetSingleState extends State<_FormInputImagesWidgetSing
662675
throw Exception('Image height is smaller than min height');
663676
}
664677

678+
679+
// TODO: use the following for image processing (other is a way too slow): https://pub.dev/packages/flutter_image_compress
680+
665681
return image.convertImage(
666682
type: widget.definition.fileSettings.conversion,
667683
quality: widget.definition.fileSettings.conversionQuality,
@@ -685,6 +701,7 @@ class _FormInputImagesWidgetSingleState extends State<_FormInputImagesWidgetSing
685701
_internalError = null;
686702
state.didChange(null);
687703
widget.definition.onChange?.call([]);
704+
_imageProvider = null;
688705
});
689706
}
690707

0 commit comments

Comments
 (0)