Skip to content

errorWidget: Not trapping HTTPException when scrolling in AnimatedList #536

Closed
@GrahamDi

Description

@GrahamDi

🐛 Bug Report

Issue: #273 also refers but has been closed, yet the issue described is still present. I am experiencing exactly the same problems as described in this comment and the possible solutions suggested would seem to be realistic: #273 (comment)

I am using FirebaseAnimatedList in a chat app to display / add-to chat messages. These messages are a mix of text and images. I use CachedNetworkImage to handle the latter and it works very well, except when there are images in error AND I scroll quickly.

In my case the errors are HttpException: Invalid statusCode: 403 - permission denied - as I am trying to handle images on Cloud Storage that may not have a valid access token.

If I allow each image in error to show its error widget (in my case, a Text widget saying no image available) before scrolling it off the screen then all is well in the universe. If I quickly scroll the several images in error either up or down, thereby not giving CachedNetworkImage the chance to fully display the error widget then the app crashes (not just a console log in debug) and my Catcher implementation reports it but only from main.dart, not anywhere that I can usefully see a specific error in the code. The scrolling does not need to be very quick.

FYI, FirebaseAnimatedList is just an implementation of Dart's AnimatedList widget that builds based on a stream from a FB RTDB query. I would anticipate that this issue would also be the case even if I used a ListViewBuilder.

Expected behavior

I would expect the errorWidget: to fully trap the 403 (or what ever other error code) even if it has not completed displaying the error widget. However, it appears that it fails to do this or even propagates the error if it is still building the error widget. In either case I am unable to trap the error myself to handle the situation gracefully and stop the app crashing.

Reproduction steps

This is my code that uses CachedNetworkImage and is called from within my FirebaseAnimatedList.

CachedNetworkImage _showMessageImage() {
    return CachedNetworkImage(
      imageUrl: _messageImageUrl,
      fit: BoxFit.cover,
      width: 250.0,
      placeholder: (context, url) => Center(
        child: AdaptiveProgressIndicator(),
      ),
      errorWidget: (context, url, error) {
        var _errorText = "${S.of(context).imageUnavailable}\n";
        if (error.statusCode == 403) {
          // Code to handle 403 error corrections on the database. 
          // Not implemented when experiencing this issue.
        }
        return Center(
          child: Text(
            _errorText,
            style: TextStyle(
                color: Colors.redAccent[700], fontWeight: FontWeight.bold),
          ),
        );
      },
    );
  }

Configuration

CachedNetworkImage: 2.5.0

flutter doctor -v
[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.21292.1000], locale en-ZA)
• Flutter version 1.22.5 at C:\flutter
• Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
• Engine revision ae90085a84
• Dart version 2.10.4

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at D:\Android
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = D:\Android
• ANDROID_SDK_ROOT = D:\Android
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[!] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.52.1)
• VS Code at C:\Users\dicki\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.18.1

[√] Connected device (1 available)
• AOSP on IA Emulator (mobile) • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

! Doctor found issues in 1 category.

Platform:

  • 📱 iOS
  • 🤖 Android

Problem occurs on emulator and device.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs more infoWe need more information before we can continue work on this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions