Repository navigation
Assert if length of TabController and number of tabs doesn't match #16292
Copy link
Copy link
Closed
Labels
frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Description
Steps to Reproduce
I have a scrollable TabBar with 11 elements. The TabBar shows the correct text for all the elements, but only the first 5 tabs are selectable, when I tap the 6th tab or further I get an exception.
Logs
Launching lib/main.dart on iPhone 6 in debug mode...
Running Xcode clean... 3.8s
Starting Xcode build...
├─Assembling Flutter resources... 10.1s
└─Compiling, linking and signing... 16.4s
Xcode build done 31.9s
Syncing files to device iPhone 6... 3.7s
🔥 To hot reload your app on the fly, press "r". To restart the app entirely, press "R".
An Observatory debugger and profiler on iPhone 6 is available at: http://127.0.0.1:8100/
For a more detailed help message, press "h". To quit, press "q".
══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
The following assertion was thrown while handling a gesture:
'package:flutter/src/material/tab_controller.dart': Failed assertion: line 111 pos 12: 'value >= 0
&& (value < length || length == 0)': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new
When the exception was thrown, this was the stack:
#2 TabController._changeIndex (package:flutter/src/material/tab_controller.dart:111:12)
#3 TabController.animateTo (package:flutter/src/material/tab_controller.dart:163:5)
#4 _TabBarState._handleTap (package:flutter/src/material/tabs.dart:865:17)
#5 _TabBarState.build.<anonymous closure> (package:flutter/src/material/tabs.dart:940:21)
#6 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:478:14)
#7 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:530:30)
#8 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#9 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
#10 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:123:7)
#11 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
#12 BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:147:20)
#13 BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
#14 BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
#15 BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
#16 BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
#17 _invoke1 (file:///b/build/slave/Mac_Engine/build/src/flutter/lib/ui/hooks.dart:134)
#18 _dispatchPointerDataPacket (file:///b/build/slave/Mac_Engine/build/src/flutter/lib/ui/hooks.dart:91)
(elided 2 frames from class _AssertionError)
Handler: onTap
Recognizer:
TapGestureRecognizer#1dc75(debugOwner: GestureDetector, state: ready, won arena, finalPosition:
Offset(270.0, 149.5), sent tap down)
Analyzing /Users/luisharo/IdeaProjects/sch_test...
No issues found!
Ran in 8.8s
Flutter Doctor
[✓] Flutter (Channel beta, v0.2.3, on Mac OS X 10.13.4 17E199, locale en-US)
• Flutter version 0.2.3 at /Users/luisharo/flutter
• Framework revision 5a58b36e36 (3 weeks ago), 2018-03-13 13:20:13 -0700
• Engine revision e61bb9ac3a
• Dart version 2.0.0-dev.35.flutter-290c576264
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at /Users/luisharo/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• 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-915-b08)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 9.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.3, Build version 9E145
• ios-deploy 1.9.2
• CocoaPods version 1.4.0
[✓] Android Studio (version 3.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
[✓] IntelliJ IDEA Community Edition (version 2018.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 23.1.3
• Dart plugin version 181.4203.498
[✓] Connected devices (2 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)
• iPhone 6 • B41B74EE-350C-4475-86D2-4306EE7B3ABF • ios • iOS 11.3 (simulator)
• No issues found!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Activity
HansMuller commentedon Apr 6, 2018
Could you provide a sample app that demonstrates this problem?
luishar0 commentedon Apr 6, 2018
I found the problem. I was creating the TabController with a length of 5, so the length in the controller and the amount of tabs created wasn't matching.
HansMuller commentedon Apr 6, 2018
This sounds like the sort of thing we should have caught earlier. Please leave the bug open and thanks for the report!
iamcksamy commentedon Aug 8, 2018
@ALL Most of the times, it was happening because of hot reload. Close the app and build it again. This should be resolved. Seems silly, I know :-) But trust me.
[-]Can only select first 5 items in TabBar, get exception on 6th and further. [/-][+]Assert if length of TabController and number of tabs doesn't match[/+]github-actions commentedon Aug 30, 2021
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 -vand a minimal reproduction of the issue.