Reputation: 151
Hi guys i want to implement flutter popover plugin i just copied the code and paste into my project as given in popover plugin link
https://pub.dev/packages/popover
but i got this error when i click the popover function
type 'RenderSliverList' is not a subtype of type 'RenderBox' in type cast
in debugMode it show error line is
final box = widget.context.findRenderObject() as RenderBox;
Upvotes: 2
Views: 5023
Reputation: 87
According to @Lulupointu answer, I try to add a builder to get a different context
Builder(builder: (context) {
return IconButton(
onPressed: () async {
final box = context.findRenderObject() as RenderBox?;
await Share.share(
subject.title.toString(),
sharePositionOrigin:
box!.localToGlobal(Offset.zero) & box.size,
);
},
icon: const Icon(
Icons.share_outlined,
color: Colors.white,
));
}),
Upvotes: 1
Reputation: 4917
This problem seems related to the other Stack Overflow question which is also about using the flutter popover package. I have an answer for it and I am referring people to look at the answer here:
Type 'RenderSliverList' is not a subtype of type 'RenderBox' in type cast
Basically you need to wrap the triggering widget ( button/textbutton/iconbutton etc.) into a class so the widget's context will be used by the popover menu items to make the popover appears at the click point of the trigger button (widget).
Upvotes: 1
Reputation: 74
I just had to change the findRenderObject() to findAncestorRenderObjectOfType().
This fixed my problem. Using findAncestorRenderObjectOfType() allowed me to find the nearest ancestor of the correct type, which solved the problem.
Upvotes: 2
Reputation: 3584
You are using the context
of a RenderSliverList
(most certainly something like SliverListDelegate
context).
The issue is that this context is inside a scrolling view, so it's render object is not a RenderBox
but a RenderSliver
.
This is important because they don't use the same constraints, which is what you want here.
The solution is to use a different context, use the one of your build
method for example and it should work.
Upvotes: 6