I want to use the errorBuilder
callback when an image asset does not exist.
But it’s not called when the Image is used with InkWell + Ink.
main() {
runApp(
MaterialApp(
home: Scaffold(
body: Center(
child: InkWell(
child: Ink.image(
image: Image.asset(
'assets/does-not-exist.png',
// Not called:
errorBuilder: (context, error, stackTrace) {
return Text('$error');
},
).image,
fit: BoxFit.cover,
height: 400,
),
onTap: () {},
),
),
),
),
);
}
2
Answers
I finally made this class in replacement of
Ink.image
:When you are calling
Image.asset(...).image
, you’re bypassing the Widget, so the error will just disappear. And it’s creating a lot of unnecessary objects. What you should be doing instead is usingAssetImage
directly (whichImage.asset
uses under the hood) and setting theInk.image
‘sonErrorBuilder
: