Parent Widget
String pincode = await Navigators.root.currentState.push(
MaterialPageRoute<String>(
builder: (context) => ChildWidget(),
),
);
Child Widget
Navigators.root.currentState.pop(pincode);
My concerns:
.pop
response to bool
.
IDE will never know and show warnings in Parent Widget.current solution
class ChildResult {
final String pincode;
ChildResult({ this.pincode });
}
class Child extends HookWidget {
...
Navigators.root.currentState.pop(ChildResult(pincode: pincode));
...
}
My current solution is to create a [Widget]Result
class,
and told my coworker to remain same practice for all widget,
so at least I can preview what's value name / type in IDE.
Is there any other solution?
As far as I know it is impossible at the moment to define a type for the pop function on the Navigator. When you call the pop the type is dynamic because it is unaware of which page (widget) it will be popped to in the stack.