Я пытаюсь отправить PhotoPathModel
между 2 виджетами AddOfferFrom
и 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
Я думаю, что TakePhoto
меньше AddOffer
что не так?