From 02e8d852f44c17ab1441c268c584831c530cdbcc Mon Sep 17 00:00:00 2001 From: Chaobin Wu Date: Mon, 22 Feb 2021 19:16:34 +0800 Subject: [PATCH] Bug fix of issue#134 Manual update tab index workaround seems not working since version 2.7.x https://github.com/hacktons/convex_bottom_bar/issues/134 --- CHANGELOG.md | 3 +++ lib/src/bar.dart | 15 +++++++++------ pubspec.yaml | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d76f50..c783c96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [2.7.1+1] +* Bug fix [Manual update tab index workaround seems not working since version 2.7.x](https://github.com/hacktons/convex_bottom_bar/issues/134) + ## [2.7.1] * fix runtime exception when there is no controller passed in diff --git a/lib/src/bar.dart b/lib/src/bar.dart index fe4d7b5..3708d77 100644 --- a/lib/src/bar.dart +++ b/lib/src/bar.dart @@ -122,6 +122,7 @@ class ConvexAppBar extends StatefulWidget { final Gradient gradient; /// The initial active index, you can config initialIndex of [TabController] if work with [TabBarView] or [PageView]. + /// If controller exists, use controller.index instead of initialActiveIndex. final int initialActiveIndex; /// Disable access of DefaultTabController to avoid unexpected conflict. @@ -253,7 +254,7 @@ class ConvexAppBar extends StatefulWidget { @required this.itemBuilder, @required this.count, this.initialActiveIndex, - this.disableDefaultTabController, + this.disableDefaultTabController = false, this.onTap, this.onTapNotify, this.controller, @@ -384,6 +385,7 @@ class ConvexAppBarState extends State ' background display with topLeft/topRight corner'), ]); } + _resetState(); super.initState(); } @@ -495,9 +497,9 @@ class ConvexAppBarState extends State } void _resetState() { - _updateTabController(); - var index = widget.initialActiveIndex ?? _controller?.index; - _currentIndex = index; + var index = _controller?.index ?? widget.initialActiveIndex; + // when both initialActiveIndex and controller are not configured + _currentIndex = index ?? 0; if (!isFixed() && _controller != null) { // when controller is not defined, the default index can rollback to 0 @@ -509,8 +511,8 @@ class ConvexAppBarState extends State @override void didChangeDependencies() { super.didChangeDependencies(); - // init state here so we can take a reference of DefaultTabController - if (_controller == null || _controller != _takeControllerRef) { + if (_controller != _takeControllerRef) { + _updateTabController(); _resetState(); } } @@ -520,6 +522,7 @@ class ConvexAppBarState extends State super.didUpdateWidget(oldWidget); if (widget.controller != oldWidget.controller || widget.count != oldWidget.count) { + _updateTabController(); _resetState(); } } diff --git a/pubspec.yaml b/pubspec.yaml index 1a08851..5483de3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: convex_bottom_bar description: A Flutter package which implements a ConvexAppBar to show a convex tab in the bottom bar. Theming supported. -version: 2.7.1 +version: 2.7.1+1 homepage: https://github.com/hacktons/convex_bottom_bar environment: