From 3c112d0efcff97d13df6d4b5cb2901619af67fe6 Mon Sep 17 00:00:00 2001 From: Sherzod <85330587+ishifr@users.noreply.github.com> Date: Wed, 17 Dec 2025 22:26:12 +0500 Subject: [PATCH] Fix TabController index update (#2753) Hi, I noticed this bug in the navigation_and_routing sample. This PR fixes the tab controller state update issue in BooksScreen. --- navigation_and_routing/lib/src/screens/books.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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'),