Flutter scrollable TabBarView in Column without predefined size

I want to have a screen with a widget at the top followed by a TabBar. I want that everything is inside a SingleChildScrollView so that the whole screen can be scrolled (not only content of a single tab).

--------------------
|      Widget      |
--------------------
|      TabBar      |
--------------------
|                  |
|                  |
|    TabBarView    |
|                  |
|                  |
--------------------

I had a look at similar questions but they did not help with what I am trying to achieve:

How to add a tab inside a column widget on flutter

Make TabBarView take up all remaining space

I cannot set a fixed height as I don't know it (tab bar content).

My approach which is not working:

class TestScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test'),
      ),
      body: SingleChildScrollView(
        child: DefaultTabController(
          length: 2,
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.all(16.0),
                child: Text('My Top Widget'),
              ),
              TabBar(
                tabs: [
                  Tab(child: Text('Available')),
                  Tab(child: Text('Taken')),
                ],
              ),
              TabBarView(
                children: [
                  Center(child: Text('1')),
                  Center(child: Text('2')),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

I get the following error:

Horizontal viewport was given unbounded height.

Viewports expand in the cross axis to fill their container and constrain their children to match their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of vertical space in which to expand.
The relevant error-causing widget was: 
  TabBarView file:///home/kay/Code/emat/frontend/lib/ui/TestScreen.dart:26:15

How it should be in the end:

Screenshot



from Recent Questions - Stack Overflow https://ift.tt/31hNm5X
https://ift.tt/3k1FnBk

Comments

Popular posts from this blog

Hibernate Search - Elasticsearch with JSON manipulation

Today Walkin 14th-Sept

Spring Elasticsearch Operations