Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add loadFailedBuilder rather than loadFailedChild #287

Closed
Aoi-hosizora opened this issue Jun 11, 2020 · 1 comment
Closed

add loadFailedBuilder rather than loadFailedChild #287

Aoi-hosizora opened this issue Jun 11, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@Aoi-hosizora
Copy link

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(); // <<<
}
@renancaraujo renancaraujo added the enhancement New feature or request label Aug 22, 2020
@renancaraujo
Copy link
Member

Should be fixed by #320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants