Open iyar-avital opened 9 months ago
This is a difficult problem to solve due to how the slide motion during the pagination is implemented. This happens when your main content has a widget with GlobalKey. During the pagination the main content widgets are duplicated in the Offstage widget to be able to calculate the size.
This is not something we can quickly fix, but I will keep an eye on this. What is your use case? If you need a form key or something similar that will be used to refer the entire widget tree, injecting the key with the KeyedSubtree
through the decorator
field would help?
This is a problem for me.
I used the key inside a Form widget, when clicking on a button the validate() function invoke on this key. The validate() function belongs to FormState class, so the key must be inside the form and the solution you gave me does not help. the
In addition, I can't use Form.of instead of the key because the Form in the content of the modal and the button is located as StickyActionBar (The form does not contain the button.)
Do you have any idea for me?
I ran into the same issue when re-using some (proprietary) form component widgets that had GlobalKey
s to scroll them into view.
Thanks @tp We are aware of this. Currently, this issue is on me and I am trying to find time to address this issue. On top of my priority list. If you want to debug and create PR, I can give you background information on the root cause.
I came up with this workaround for the app I am working on, where gladly we control all child widgets of the modal:
@override
Widget build(BuildContext context) {
final isOffstage =
context.findAncestorWidgetOfExactType<Offstage>()?.offstage == true;
return Widget(
// Do not set the key when rendering offstage (e.g. WoltModalSheet) to avoid duplicate `GlobalKey`s
// (This will not impact any behavior as these are only needed for scrolling on-screen widgets anyway)
key: isOffstage ? null : fieldItem.widgetKey,
Very smart workaround! I will give a shot to a more proper solution. It is nice to know that a workaround is possible.
I have the same issue, will remove the Form from the widget for now.
Any new solutions? When i use
final isOffstage = context.findAncestorWidgetOfExactType<Offstage>()?.offstage == true;
On first page i got wrong true
and i cant validate forms (for example).
But when change to any pages and going back, got right false
.
UPD. I found solution, looks bad but works. Will be waiting maybe anyone suggest more elegant solution.
class _SignInWoltpageState extends State<SignInWoltpage> {
bool isOffstageFromDelayedCheck = true;
@override
void initState() {
super.initState();
checkVisibilityInitially();
}
void checkVisibilityInitially() {
Future.delayed(const Duration(milliseconds: 50), () {
if (!mounted) return;
setState(() {
isOffstageFromDelayedCheck = context.findAncestorWidgetOfExactType<Offstage>()?.offstage ?? false;
});
});
}
@override
Widget build(BuildContext context) {
final isOffstageFromBuildCheck = context.findAncestorWidgetOfExactType<Offstage>()?.offstage ?? true;
final isOffstage = isOffstageFromDelayedCheck && isOffstageFromBuildCheck;
Is there meanwhile another Solution?
Bug report
Duplicate global key on the content on the first page from two pages when moving to the second page.
Steps to reproduce
Steps to reproduce the behavior:
Expected behavior
The first page does not need to be rebuilt when moving to the second page