Skip to content

Allow intrinsic height #37

@fjelljager

Description

@fjelljager

Hi, I have another question about TabbedView if you would be willing to help me out,

I've been trying to implement TabbedView inside a column and would like it to resize so that the height equals the height of the selected tab content (instead of double.infinity).

To illustrate:
I extended the example code so that TabbedView is in a column with another Container. The TabbedView is constrained to a fixed height and everything works as expected:
image

class TabbedViewExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false, home: TabbedViewExamplePage());
  }
}

class TabbedViewExamplePage extends StatefulWidget {
  @override
  _TabbedViewExamplePageState createState() => _TabbedViewExamplePageState();
}

class _TabbedViewExamplePageState extends State<TabbedViewExamplePage> {
  late TabbedViewController _controller;

  @override
  void initState() {
    super.initState();
    List<TabData> tabs = [];

    tabs.add(TabData(
        text: 'Tab 1',
        leading: (context, status) => Icon(Icons.star, size: 16),
        content: Padding(child: Text('Hello'), padding: EdgeInsets.all(8))));
    tabs.add(TabData(
        text: 'Tab 2',
        content:
            Padding(child: Text('Hello again'), padding: EdgeInsets.all(8))));
    tabs.add(TabData(
        closable: false,
        text: 'TextField',
        content: Padding(
            child: TextField(
                decoration: InputDecoration(
                    isDense: true, border: OutlineInputBorder())),
            padding: EdgeInsets.all(8)),
        keepAlive: true));

    _controller = TabbedViewController(tabs);
  }

  @override
  Widget build(BuildContext context) {
    TabbedView tabbedView = TabbedView(controller: _controller);
    Widget w =
        TabbedViewTheme(child: tabbedView, data: TabbedViewThemeData.mobile());
    return Scaffold(body: Container(child: Column(
      children: [
        Container(
          color: Colors.blue,
          child: SizedBox(
            width: double.infinity,
            height: 400,
            child: w
          ),
        ),
        Expanded(
          child: Container(
            color: Colors.green,
            child: SizedBox(width: double.infinity,),
          ),
        )
      ],
    ), padding: EdgeInsets.all(32)));
  }
}

The problem occurs when I comment out height: 400 for the SizedBox around the TabbedView. I was expecting the TabbedView to shrink to the size of the content, but instead I get the following error:

image
The following assertion was thrown during performLayout():
RenderCustomMultiChildLayoutBox object was given an infinite size during layout.

This probably means that it is a render object that tries to be as big as possible, but it was put inside another render object that allows its children to pick their own size.
The nearest ancestor providing an unbounded height constraint is: RenderFlex#c885f relayoutBoundary=up2 OVERFLOWING
...  needs compositing
...  parentData: offset=Offset(32.0, 32.0) (can use size)
...  constraints: BoxConstraints(0.0<=w<=593.8, 0.0<=h<=564.8)
...  size: Size(621.8, 576.0)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
The constraints that applied to the RenderCustomMultiChildLayoutBox were: BoxConstraints(w=593.8, 0.0<=h<=Infinity)
The exact size it was given was: Size(593.8, Infinity)

See https://flutter.dev/docs/development/ui/layout/box-constraints for more information.

Please could you let me know if this is a bug in TabbedView or if I just have a bad understanding of the layout system in Flutter and need to revise that? If the latter then and suggestions would be appreciated. Thank you for your time in advance!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions