Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

实际使用中遇到一个PhotoPickerProvider.of(context)的问题求解 #118

Open
gaoyong06 opened this issue Apr 14, 2020 · 3 comments
Open
Labels
help wanted Extra attention is needed

Comments

@gaoyong06
Copy link

gaoyong06 commented Apr 14, 2020

我现在遇到一个很难解决的问题

问题是这样:
我有一个 页面A页面A 里面有个 子组件B 页面A 里面还有个 按钮C

点击 按钮C 打开相册选择图片,选择完以后,在 子组件B 里面展示图片,然后在 点击子组件B 里面点击一个图片的时候,希望可以进入 flutter_photo 的预览页面 可以继续进行选择图片,或者取消该图片的选择(就是编辑的意思)

页面A: 是StatefulWidget
子组件B: 是封装后的一个GridView
按钮C: 是一个封装后的Button

我翻了一下flutter_photo项目里面的代码,发现有下面这个方法,可以实现我的想法:
`

///点击发布动态页内图片回调
///点击已选择图片中的任意一张图
///参考文档:https://github.com/CaiJingLong/flutter_photo/blob/1455ea92fd56e89a2c6f27490b97eab84636c303/lib/src/ui/page/photo_main_page.dart
///
void _onItemClick(BuildContext context, AssetEntity data, int index) {

print("========== _onItemClick 开始执行============");
PhotoPickerProvider photoPickerProvider = PhotoPickerProvider.of(context);
print(photoPickerProvider);

PhotoOptions.Options options = PhotoPickerProvider.of(context).options;
AssetProvider assetProvider = PhotoPickerProvider.of(context).assetProvider;

var result = PhotoPreviewResult();
// isPushed = true;
Navigator.of(context).push(
  MaterialPageRoute(
    builder: (ctx) {
      return PhotoPickerProvider(
        provider: PhotoPickerProvider.of(context).provider,
        options: options,
        child: PhotoPreviewPage(
          // selectedProvider: this,

          //TODO:这里设置为null会不会有问题?
          selectedProvider: null,
          list: List.of(assetFeedImageList),
          initIndex: index,
          changeProviderOnCheckChange: true,
          result: result,
          isPreview: false,
          assetProvider: assetProvider,
        ),
      );
    },
  ),
).then((v) {
  if (handlePreviewResult(v)) {
    Navigator.pop(context, v);
    return;
  }
  // isPushed = false;
  // setState(() {});
});

}

`

上面的代码我做了一些修改,问题是这个方法执行的时候,PhotoPickerProvider.of(context) 一直是null

打印的日志信息是:

I/flutter (30355): ========== _onItemClick 开始执行============
I/flutter (30355): null
I/flutter (30355): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (30355): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter (30355): The getter 'options' was called on null.
I/flutter (30355): Receiver: null
I/flutter (30355): Tried calling: options
I/flutter (30355): When the exception was thrown, this was the stack:
I/flutter (30355): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)

我看在项目里面 有使用PhotoPickerProvider 会把子组件包一下,但是这个包的时候,需要提供 options等参数,这个参数 我在页面A也拿不到?

请问一下,PhotoPickerProvider.of(context).options 我在页面A,或者组件B 里面应该如何处理?

@gaoyong06 gaoyong06 added the help wanted Extra attention is needed label Apr 14, 2020
@gaoyong06
Copy link
Author

我有想用 PhotoPickerProvider 把 页面A 包一下, 但是

里面页面A里面的build方法的实现,类似下面这样

`
@OverRide
Widget build(BuildContext context) {
return PhotoPickerProvider(

  child: Scaffold.....
  options: <?>, 
  provider: <?>,

)
`

但是这个 options, 和 provider 该怎么写?

@CaiJingLong
Copy link
Owner

CaiJingLong commented Apr 14, 2020

I have newly developed a library photo_widget, which can be combined with any control to help you quickly develop this kind of scene. But that library is still in the early development version, there is no documentation, you may need to check the example / library source code to familiarize yourself with the use of APIs.

pub: https://pub.dev/packages/photo_widget
github: https://github.com/fluttercandies/photo_widget

@CaiJingLong
Copy link
Owner

image
All widgets can be used externally relatively simply and independently.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants