Skip to content

TabController indexIsChanging always return false when swiping TabBarView #28298

Closed

Description

@yudaprama

Steps to Reproduce

class MyTabbedPage extends StatefulWidget {
	const MyTabbedPage({ Key key }) : super(key: key);
	@override
	_MyTabbedPageState createState() => _MyTabbedPageState();
}

class _MyTabbedPageState extends State<MyTabbedPage> with SingleTickerProviderStateMixin {
	final List<Tab> myTabs = <Tab>[
		Tab(text: 'LEFT'),
		Tab(text: 'RIGHT'),
	];

	TabController _tabController;

	@override
	void initState() {
		super.initState();
		_tabController = TabController(vsync: this, length: myTabs.length);
		_tabController.addListener(() {
			print('indexIsChanging: ${_tabController.indexIsChanging}'); // always false
		});
	}

	@override
	void dispose() {
		_tabController.dispose();
		super.dispose();
	}

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				bottom: TabBar(
					controller: _tabController,
					tabs: myTabs,
				),
			),
			body: TabBarView(
				controller: _tabController,
				children: myTabs.map((Tab tab) {
					return Center(child: Text(tab.text));
				}).toList(),
			),
		);
	}
}
  1. Tap TabBar, indexIsChanging return true
  2. Swipe TabBarView, indexIsChanging return false

Logs

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.2 18C54, locale en-ID)
    • Flutter version 1.0.0 at /Users/yuda/flutter
    • Framework revision 5391447fae (3 months ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/yuda/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/yuda/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 33.1.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[✓] Connected device (1 available)
    • iPhone X • A29A6A52-4245-4904-8ED4-D10AE01FBD8D • ios • iOS 12.1 (simulator)

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    on Feb 22, 2019
  2. added this to the milestone on Feb 22, 2019
  3. HansMuller commented on Feb 28, 2019

    @HansMuller
    Contributor

    The indexIsChanging property is a bit of a misnomer. Its value is true when the controller animation's value is changing from one value to another because the user tapped a tab, but not when the animation's value is changing because the user is dragging the TabBarView.

    Here's a version of your example that demos the difference: https://gist.github.com/HansMuller/ba3f841296bacc6522b99b8d474286b5

    The documentation could be clearer about this; will fix it.

  4. self-assigned this
    on Feb 28, 2019
  5. sultanmyrza commented on Apr 27, 2020

    @sultanmyrza

    If you want change bottom bar selected icon after swipe you can try this

    _tabController.addListener(() {
          setState(() {
            _currentIndex = _tabController.index;
          });
        });
    

    here is the full gist
    https://gist.github.com/sultanmyrza/36f6726e563f9c6bacf9ad0e4a47b807

  6. github-actions commented on Aug 14, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions