I am making a split-view widget that can adjust their ratio by dragging bottom widget. The thing is that I want to put some big widget on the bottom so that it can be seen fully when I extend it, only partially if not.
And here's my code for split view.
class HorizontalSplitView extends StatefulWidget {
final Widget top;
final Widget bottom;
final double ratio;
const HorizontalSplitView(
{Key key, @required this.top, @required this.bottom, this.ratio = 0.2})
: super(key: key);
@override
_HorizontalSplitViewState createState() => _HorizontalSplitViewState();
}
class _HorizontalSplitViewState extends State<HorizontalSplitView> {
double _ratio;
double _maxHeight;
get _height1 => _ratio * _maxHeight;
get _height2 => (1 - _ratio) * _maxHeight;
@override
void initState() {
super.initState();
_ratio = widget.ratio;
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, BoxConstraints constraints) {
_maxHeight = constraints.maxHeight;
return SizedBox(
height: constraints.maxHeight,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SizedBox(
height: _height1,
child: widget.top,
),
GestureDetector(
behavior: HitTestBehavior.translucent,
onPanUpdate: (DragUpdateDetails details) {
setState(() {
_ratio += details.delta.dy / _maxHeight;
if (_ratio > 0.85)
_ratio = 0.85;
else if (_ratio < 0.0) _ratio = 0.0;
});
},
onPanEnd: (DragEndDetails details) {
setState(() {
if (_ratio < 0.5)
_ratio = 0.0;
else if (0.6 <= _ratio && _ratio < 0.8)
_ratio = 0.6;
else if (0.8 < _ratio) _ratio = 0.85;
});
},
child: SizedBox(
height: _height2,
child: widget.bottom,
),
),
],
),
);
});
}
}
The thing is if I put scrollchildview with boxconstraint height instead of sized box widget It throws overflow error. Is there any way to put scrollview or any other widget that can be located in determined height sizedBox widget? Thanks in advance.
Solved by changing layout as Stack like below