Apparently, I am having this error when I navigate to my photo view page and then back to the previous page.
======== Exception caught by widgets library =======================================================
The following assertion was thrown while finalizing the widget tree:
Looking up a deactivated widget's ancestor is unsafe.
At this point the state of the widget's element tree is no longer stable.
To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
====================================================================================================
I have search for similar problems available in stackoverflow but I just cant find the related ones.
Below is part of the codes to route into the photo view page
FutureBuilder(
future: storage.downloadURL(annData.imagePath[index]),
builder: (BuildContext context,
AsyncSnapshot<String> snapshot) {
if(snapshot.connectionState == ConnectionState.done && snapshot.hasData)
{
return Card(
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: InkWell(
onTap: (){
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => GalleryWidget(
urlImages: snapshot.data!,
),
));
},
child: Container(
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.network(
snapshot.data!,
fit:BoxFit.cover,
),
),
),
),
);
}
if(snapshot.connectionState == ConnectionState.waiting)
{
return Loading();
}
return Container();
},
);
}),
),
] else ...[
Container(),
],
And here is my photo view page
class GalleryWidget extends StatelessWidget {
final String urlImages;
GalleryWidget({required this.urlImages});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).primaryColor,
elevation: 0.0,
),
body: Center(
child: PhotoView(
imageProvider: NetworkImage(urlImages),
),
),
);
}
}
After entering the gallerywidget page and back to the previous page, my existing functions such as delete or edit are all messed up. Please help me on this issue.
I try changing from stateful to stateless widget and the problems is still the same. Please forgive me as my knowledge on debugging is still at a beginner stage.
So while i was browsing the github repository for photo_view:
there is a comment saying to change the version in pubspec.yaml into this
after running pubget, i am not getting anymore issues. I hope this can help others.