Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabView inside CustomScrollView

Tags:

flutter

Wrapping TabBarView with SliverFillRemaining (fill remaining empty space like Expanded) gives the following error output.

flutter: A RenderPositionedBox expected a child of type RenderBox but received a child of type flutter: RenderSliverList.

TabController tabContoller;
    @override
  void initState() {
    tabContoller = new TabController(
      vsync: this,
      length: 3,
    );


 @override
 Widget build(BuildContext context) {
    return new Scaffold(
        floatingActionButton:floatActionBtn(...),
        bottomNavigationBar: bottomNavigationBar(...),
        appBar: apBar(),
        body: Stack(
          children: <Widget>[
            CustomScrollView(
              slivers: <Widget>[
                SliverAppBar(
                  backgroundColor: Colors.transparent,
                  automaticallyImplyLeading: false,
                  expandedHeight: 195.0,
                  flexibleSpace: FlexibleSpaceBar(
                    background: new Stack(
                        children: <Widget>[
                          ...

                        ]),
                  ),
                ),
                  new SliverFillRemaining(
                    child: TabBarView(
                      controller: tabContoller,
                      children: <Widget>[
                        Tab(...),
                        Tab(...),
                        Tab(...)
                      ],
                    ),
                  ),
              ],
            ),
          ],

        )
like image 532
Jamie White Avatar asked Jan 06 '19 22:01

Jamie White


1 Answers

Don't forget the DefaultTabController, this code is working fine:

         @override
          Widget build(BuildContext context) {
            return DefaultTabController(
              length: 3,
              child: Container(
                  child: CustomScrollView(slivers: <Widget>[
                SliverAppBar(),
                new SliverFillRemaining(
                  child: TabBarView(
                    children: <Widget>[
                      Text("Tab 1"),
                      Text("Tab 2"),
                      Text("Tab 3"),
                    ],
                  ),
                ),
              ])),
            );
          }
like image 132
diegoveloper Avatar answered Nov 11 '22 14:11

diegoveloper