mirror of
https://github.com/flutter/samples.git
synced 2026-03-21 20:08:16 +00:00
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.
This commit is contained in:
@@ -31,6 +31,14 @@ class _BooksScreenState extends State<BooksScreen>
|
|||||||
..addListener(_handleTabIndexChanged);
|
..addListener(_handleTabIndexChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant BooksScreen oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (oldWidget.selectedIndex != widget.selectedIndex) {
|
||||||
|
_tabController.index = widget.selectedIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_tabController.removeListener(_handleTabIndexChanged);
|
_tabController.removeListener(_handleTabIndexChanged);
|
||||||
@@ -39,7 +47,6 @@ class _BooksScreenState extends State<BooksScreen>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
_tabController.index = widget.selectedIndex;
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Books'),
|
title: const Text('Books'),
|
||||||
|
|||||||
Reference in New Issue
Block a user