How to restrain DataTable to just expand on max height or lower

36 views Asked by At

I have a layout in Flutter where I have a DataTable which should just expand into its contents, or to definite max height (in this example it would be 200). The DataTable definition is contained into two SingleChildScrollViews scrolling height and width.

It looks like this: enter image description here

But this results into a blank field below... I thought the DataTable would shrink its height, but it doesn't.

The code principle is like this:

Scaffold(
  body: LayoutBuilder(
    builder: (context, constraints){
      ...
      return Row(
        children: [
          Expanded(...),
          Expanded(
            flex: 3,
            child: Column(
              children: [
                Expanded(...),
                Expanded(
                  child: Container(
                    constraints: const BoxConstraints(
                      maxHeight: 200,
                      child: Column(
                        crossAxisAlignment:CrossAxisAlignment.stretch,
                        children: [
                          Expanded(
                            child: SingleChildScrollView(
                              scrollDirection: Axis.vertical,
                              child: SingleChildScrollView(
                                physics: const ClampingScrollPhysics(),
                                scrollDirection: Axis.horizontal, 
                                child: DataTable(...) 
                              ) 
                            )   
                          )   
                        ]
                      )  
                    )
                  )
                ),
              ]
            )
          )       
        ]
      )
      ...
    } 
  )
)

My challenge is like this: I want my table to shrink to it containing height, but never be higher than 200, and full scrollable both vertically (if it passes height of 200) and horizontally, and it needs to be in the bottom of my screen/view.

0

There are 0 answers