diff --git a/navigation_and_routing/lib/src/screens/books.dart b/navigation_and_routing/lib/src/screens/books.dart index 1557da5ba..cc2241b99 100644 --- a/navigation_and_routing/lib/src/screens/books.dart +++ b/navigation_and_routing/lib/src/screens/books.dart @@ -31,6 +31,14 @@ class _BooksScreenState extends State ..addListener(_handleTabIndexChanged); } + @override + void didUpdateWidget(covariant BooksScreen oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.selectedIndex != widget.selectedIndex) { + _tabController.index = widget.selectedIndex; + } + } + @override void dispose() { _tabController.removeListener(_handleTabIndexChanged); @@ -39,7 +47,6 @@ class _BooksScreenState extends State @override Widget build(BuildContext context) { - _tabController.index = widget.selectedIndex; return Scaffold( appBar: AppBar( title: const Text('Books'),