Skip to content

add loadFailedBuilder rather than loadFailedChild #287

@Aoi-hosizora

Description

@Aoi-hosizora

Version: photo_view: ^0.9.2

Is your feature request related to a problem? Please describe.

I use PhotoViewGallery with my customer ImageProvider.
I want to show the error message generated by (customer or not) ImageProvider. But I find there is only a loadFailedChild property. I hope it can wrap by a function.

Describe the solution you'd like

In photo_view.dart, use _loadFailedError rather then _loadFailed:

// 1.
Future<ImageInfo> _getImage() {
  // xxx
  }, onChunk: (event) {
    if (mounted) {
      setState(() => _imageChunkEvent = event);
    }
  }, onError: (exception, stackTrace) {
    if (!mounted) {
      return;
    }
    setState(() {
      // _loadFailed = true;
      _loadFailedError = exception ?? 'unknown error'; // <<<
   });
    /* FlutterError.reportError(
      FlutterErrorDetails(exception: exception, stack: stackTrace),
    ); */
  });
  stream.addListener(listener);
  completer.future.then((_) {
    stream.removeListener(listener);
  });
  return completer.future;
}

// 2.
@override
Widget build(BuildContext context) {
  return _loadFailedError != null
      ? _buildLoadFailed() // <<<
      : LayoutBuilder(
          builder: (
            BuildContext context,
            BoxConstraints constraints,
          ) {
            return widget.child == null
                ? _buildImage(context, constraints)
                : _buildCustomChild(context, constraints);
          },
        );
}

// 3.
Widget _buildLoadFailed() {
  return widget.loadFailedBuilder(_loadFailedError) ?? PhotoViewDefaultError(); // <<<
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions