Skip to content

[Bug report] Bad state: Failed to load https://oss-zjrs.haier.net/app/weather_img/bg_cloudy_7302.webp #749

@limengyue-ha

Description

@limengyue-ha

Version

extended_image-8.2.0/extended_image_library-4.0.2

Platforms

dart

Device Model

iPhone

flutter info

[!] Flutter (Channel [user-branch], 3.22.3, on macOS 15.4.1 24E263 darwin-x64, locale zh-Hans-CN)
    ! Flutter version 3.22.3 on channel [user-branch] at /Users/wanghui/ws/flutter/flutter3
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    • Framework revision b0850beeb2 (1 year, 2 months ago), 2024-07-16 21:43:41 -0700
    • Engine revision 235db911ba
    • Dart version 3.4.4
    • DevTools version 2.34.3
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3)
    • Android SDK at /Users/wanghui/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0-rc3
    • ANDROID_HOME = /Users/wanghui/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16E140
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)

[✓] VS Code (version 1.103.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.116.0

[✓] Connected device (3 available)
    • PEDM00 (mobile) • af833fbc • android-arm64  • Android 14 (API 34)
    • macOS (desktop) • macos    • darwin-x64     • macOS 15.4.1 24E263 darwin-x64
    • Chrome (web)    • chrome   • web-javascript • Google Chrome 139.0.7258.155
    ! Error: Browsing on the local area network for 李梦月的iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

How to reproduce?

I'm not sure how to generate this error, it can also occur when there are no network issues

Logs

'Bad state: Failed to load https://oss-zjrs.haier.net/app/weather_img/bg_cloudy_7302.webp.'

Example code (optional)

class _CommonNetWorkImage extends State<CommonNetWorkImage> {
  bool isImageLoadFail = false;
  bool reload = false;

  @override
  void didUpdateWidget(CommonNetWorkImage oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (oldWidget.needReload != widget.needReload) {
      if (isImageLoadFail) {
        setState(() {
          reload = true;
        });
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return (widget.url == null || widget.url == '')
        ? widget.errorWidget ?? Container()
        : _loadImage(context);
  }

  Widget _loadImage(BuildContext context) {
    final double scale = MediaQuery.of(context).devicePixelRatio;
    int? cacheHeight =
        widget.height != null ? (widget.height! * scale).toInt() : null;
    String providerUrl = '';
    if (widget.withOssParam == true &&
        (widget.width != null || widget.height != null)) {
      providerUrl = OssUtil.addOssParams(widget.url ?? '', widget.width, widget.height);
    } else {
      providerUrl = widget.url ?? '';
    }

    return ExtendedImage(
        alignment: widget.alignment ?? Alignment.center,
        width: widget.width,
        height: widget.height,
        fit: widget.fit ?? BoxFit.contain,
        image: ResizeImage.resizeIfNeeded(
            null, cacheHeight, CommonNetWorkImageProvider.get(providerUrl)),
        loadStateChanged: (ExtendedImageState state) {
          switch (state.extendedImageLoadState) {
            case LoadState.loading:
              return widget.placeHolder ?? Container();
            case LoadState.failed:
              isImageLoadFail = true;
              if (reload) {
                state.reLoadImage();
                reload = false;
              }
              return widget.errorWidget ?? Container();
            case LoadState.completed:
              isImageLoadFail = false;
              if (widget.addRepaintBoundaries == false) {
                return null;
              }

              if (widget.addRepaintBoundaries == true ||
                  state.frameNumber != null && state.frameNumber! > 0) {
                return RepaintBoundary(child: state.completedWidget);
              }
             
              return null;
          }
        });
  }
}

class CommonNetWorkImageProvider {
  static ImageProvider get(String url) {
    return ExtendedNetworkImageProvider(
      url,
      cache: true,
      cacheMaxAge: Duration(days: 7),
    );
  }
}

Contact

1425634445@qq.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions