Returning a Scaffold with a TabBarView child gives Exception : Failed assertion: 'pixels !=null':

578 views
Skip to first unread message

Rajesh Khan

unread,
Jun 13, 2018, 7:27:07 AM6/13/18
to Flutter Dev
I currently have a TabBarView.The TabBarView has 4 pages. It starts with PageA and that runs fine. Now if I move to PageC directly from pageA then I get the following exception. I noticed this is because of PageB (since the path to PageC is connected via PageB I guess. I am not sure why) Anyways I noticed this problem is fixed if I remove the TabBarView which is being returned from PageB. Any ideas why PageB returning back a TabBarView is returning back an exception when toggling from PageA to PageC ? Is this a Framework issue ?

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown while finalizing the widget tree:
flutter: 'package:flutter/src/widgets/scroll_position.dart': Failed assertion: line 627 pos 12: 'pixels !=
flutter: null': is not true.
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter:   https://github.com/flutter/flutter/issues/new
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2      ScrollPosition.dispose (package:flutter/src/widgets/scroll_position.dart)
flutter: #3      ScrollPositionWithSingleContext.dispose (package:flutter/src/widgets/scroll_position_with_single_context.dart:260:11)
flutter: #4      ScrollableState.dispose (package:flutter/src/widgets/scrollable.dart:324:14)
flutter: #5      StatefulElement.unmount (package:flutter/src/widgets/framework.dart:3821:12)
flutter: #6      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1697:13)
flutter: #7      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1695:7)
flutter: #8      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3676:14)
flutter: #9      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1693:13)


which looks like this. This is how it starts

tabBarView = new TabBarView(controller: _tabController, children: <Widget>[
      new pageA(),
      new pageB(),
      new pageC(),
      new pageD(),
    ]);

Now pageB itself has a TabBarView that looks like this

tabBarView = new TabBarView(controller: _tabController, children: <Widget>[
              new foo(),
              new foo(),
        ]);

The build method of pageB (which is the problem) looks like this

@override
   Widget build(BuildContext context) {
       var scaffold = Scaffold(
           appBar: new AppBar(
               automaticallyImplyLeading: false,
               bottom: new PreferredSize(
                   preferredSize: new Size(200.0, 15.0),
                   child: new Container(
                       width: 200.0,
                       child: new TabBar(
                           controller: _tabController,
                           tabs: [
                               new Container(
                                   child: new Tab(text: 'Tab1 - Inside PageB'),
                                   ),
                               new Container(
                                   child: new Tab(text: 'Tab2 - Inside PageB'),
                                   ),
                           ],
                           ),
                       ),
                   ),
               ),
           body: tabBarView, //!!!!!!!!! Removing this Solves the problem
           );

       return scaffold;
   }

As you can see the problem is somewhere in PageB. However I am switching from PageA to PageC. I dont know why PageB is involved.IF I try to load PageB it loads fine. I think it has to do with disposing of PageB resources or something. I would appreciate it if someone could explain what exactly is happening here and any ideas on how I can fix this ?

Reply all
Reply to author
Forward
0 new messages