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.
main
Sherzod 4 weeks ago committed by GitHub
parent 6f4e07c9dd
commit 3c112d0efc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -31,6 +31,14 @@ class _BooksScreenState extends State<BooksScreen>
..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<BooksScreen>
@override
Widget build(BuildContext context) {
_tabController.index = widget.selectedIndex;
return Scaffold(
appBar: AppBar(
title: const Text('Books'),

Loading…
Cancel
Save