Inside my widget
I have some images
. These images
have a position
. I would like to check if an image with a certain position exists, show it. Else the child
of my GestureDetector
should simply be nothing.
This is what I tried:
child: GestureDetector(
onTap: () => print("tapped 1"),
onScaleStart: (details) {
_startingFocalPoint.value = details.focalPoint;
_previousOffset.value = _offset.value;
_previousZoom.value = _zoom.value;
},
onScaleUpdate: (details) {
_zoom.value = _previousZoom.value * details.scale;
final Offset normalizedOffset =
(_startingFocalPoint.value - _previousOffset.value) /
_previousZoom.value;
_offset.value =
details.focalPoint - normalizedOffset * _zoom.value;
},
child: widget.images.where(
(image) => image.position == ImagePosition.ONE) !=
null
? ClipPath(
clipper: _Position1ClipperImage(),
child: Transform(
transform: Matrix4.identity()
..translate(_offset.value.dx, _offset.value.dy)
..scale(_zoom.value),
child: Image.asset(
widget.images
.firstWhere(
(image) => image.position == ImagePosition.ONE,
)
.path,
width: widget.width,
height: widget.width,
fit: BoxFit.fill),
),
)
: null,
),
But if there is no image
with ImagePosition.ONE
, I get a Bad State: No elemnt
- Error.
What am I missing here?
Let me know if you need any more details!