找不到正确的提供者<

时间:2020-04-22 16:55:32

标签: flutter provider

我正在尝试在2个小部件PhotoPathModelAddOfferFrom之间发送TakePhoto。 编辑:树看起来像这样

[AddOffer] -> The child of Provider<PhotoPathModel>
|_ [AddOfferForm] -> Includes a button which push the `TakePhoto` route

我有这些课 AddOffer

    return MultiProvider(
      providers: [
         ...
         ChangeNotifierProvider<PhotoPathModel>(
           create: (context) => PhotoPathModel(),
         )
         ...
      ],
...

                ....
                    child: AddOfferForm(
              camera: camera,
            ))),
...

和具有该按钮的AddOfferForm类

       CustomButton(
                  text: "Add state image",
                  onTap: (){
                   Navigator.push(context, MaterialPageRoute(builder: (context) => 
        TakePhoto(camera: widget.camera))) ;
                  }),

Consumer<PhotoPathModel>(
    builder: (context,path,child){
          if(path.path !=null){
                   return Image.file(File(path.path)) ;
           }
             return Container();
            }
        ),

和具有

的TakePhoto类
      floatingActionButton: FloatingActionButton(
        onPressed: () async { try {
            await _initializeCamerController;
            Provider
                .of<PhotoPathModel>(context, listen: false)
                .path = join(
                (await getTemporaryDirectory()).path, '${DateTime.now()}.png');
            await _cameraController.takePicture(
                Provider
                    .of<PhotoPathModel>(context, listen: false)
                    .path);
          } catch (e) {
....

这是错误

I/flutter ( 1578): Error: Could not find the correct Provider<PhotoPathModel> above this TakePhoto Widget
I/flutter ( 1578): 
I/flutter ( 1578): To fix, please:
I/flutter ( 1578): 
I/flutter ( 1578):   * Ensure the Provider<PhotoPathModel> is an ancestor to this TakePhoto Widget
I/flutter ( 1578):   * Provide types to Provider<PhotoPathModel>
I/flutter ( 1578):   * Provide types to Consumer<PhotoPathModel>
I/flutter ( 1578):   * Provide types to Provider.of<PhotoPathModel>()
I/flutter ( 1578):   * Ensure the correct `context` is being used.
I/flutter ( 1578): 
I/flutter ( 1578): If none of these solutions work, please file a bug at:
I/flutter ( 1578): https://github.com/rrousselGit/provider/issues

我认为TakePhotoAddOffer下是怎么了?

0 个答案:

没有答案