How to get frameBuilder and loadingBuilder to work togerther ?
"loadingBuilder" works all the time (with or without frameBuilder) but "frameBuilder" works only if it is alone (i.e. commenting loadingBuilder out).
The documentation talks about "chaining" frameBuilder with loadingBuilder, it's not obvious that is something happens internally or it is something we have to consider.
Image.network(_imageUrl,
height: 400,
width: MediaQuery.of(context).size.width,
fit: BoxFit.fitWidth,
frameBuilder: (BuildContext context, Widget child, int frame, bool wasSynchronouslyLoaded) {
if (wasSynchronouslyLoaded) return child;
return AnimatedOpacity(
opacity: frame == null ? 0 : 1,
duration: Duration(seconds: 5),
curve: Curves.easeOut,
child: child,
);
},
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null ?
loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes :
null,
),
);
},
errorBuilder: (BuildContext context, Object exception, StackTrace stackTrace) {
return Text('Failed to load image');
},
),
Edit:
What Happens Exactly:
Case 1: When loadingBuilder is ALONE the CircularProgressIndicator is showing and the loading process is completed then the indicator disappears and the loaded image is showing without fading. (Perfect)
Case 2: When frameBuilder is ALONE the image takes its time to load (of cource there is the indicator), then the loaded image is showing gradually as expected. (Perfect)
Case 3: When the frameBuilder and loadingBuilder BOTH are enabled, what happened is CASE 1 exactly without any fading of the image. (Wrong)
Expected Behavior:
The indicator is shown while the loading process is going, then disappear and the image is shown with fading effect.
I need to fix this code and figure out where is the problem.