Open GodCodeWeed opened 2 years ago
I was having the same issue; Returning the PersistentTabView directly from the build was not an option for me; Having the a scaffold Key instantiated outside the build method should do the trick:
class _YourWidgetState extends State<YourWidget> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
...
...
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
same problem, none of your solutions worked.
I found a solution,
I am using persistent_bottom_nav_bar: ^4.0.2
This happens because of line 371 in the lib/models/persistent-nav-bar-scaffold.widget.dart
file
In the _focusActiveTab function:
void _focusActiveTab() {
if (widget.screenTransitionAnimation!.animateTabTransition)
_newPageAnimation();
if (tabFocusNodes.length != widget.tabCount) {
if (tabFocusNodes.length > widget.tabCount!) {
discardedNodes.addAll(tabFocusNodes.sublist(widget.tabCount!));
tabFocusNodes.removeRange(widget.tabCount!, tabFocusNodes.length);
} else {
tabFocusNodes.addAll(
List<FocusScopeNode>.generate(
widget.tabCount! - tabFocusNodes.length,
(int index) => FocusScopeNode(
debugLabel:
'$CupertinoTabScaffold Tab ${index + tabFocusNodes.length}'),
),
);
}
}
// FocusScope.of(context).setFirstFocus(tabFocusNodes[widget.currentTabIndex]);
if (widget.screenTransitionAnimation!.animateTabTransition)
_lastPageAnimation();
}
Commenting out FocusScope.of(context).... line fixes this error, this is the line:
FocusScope.of(context).setFirstFocus(tabFocusNodes[widget.currentTabIndex]);
I don't know if this line is important, seems like it is not because I don't notice any other unexpected behavior
I had the same issue, what worked for me was returning the PersistentTabView directly from the build as opposed to having it inside a Scaffold.