build method
构建最终的 Widget
Implementation
Widget build() {
// 如果需要双向滚动
if (_enableScrollX && _enableScrollY) {
return SingleChildScrollView(
scrollDirection: Axis.vertical,
physics: _physics,
controller: _controller,
padding: _padding,
clipBehavior: _clipBehavior,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
physics: _physics,
clipBehavior: _clipBehavior,
child: child,
),
);
}
// 如果只需要单向滚动
if (_enableScrollX || _enableScrollY) {
return SingleChildScrollView(
scrollDirection: _scrollDirection ?? (_enableScrollY ? Axis.vertical : Axis.horizontal),
physics: _physics,
controller: _controller,
padding: _padding,
clipBehavior: _clipBehavior,
child: child,
);
}
// 如果不需要滚动,只是裁剪
if (_clipBehavior != Clip.none) {
return ClipRect(
clipBehavior: _clipBehavior,
child: child,
);
}
// 允许溢出显示
return child;
}