可容纳一个子组件,通过指定最大宽高来限定子组件容身区域。
相关组件
LimitedBox基本使用
<br />【child】 : 孩子组件 【Widget】<br />【maxHeight】 : 最大高 【double】<br />【maxWidth】 : 最大宽 【double】<br />![189.gif](https://cdn.nlark.com/yuque/0/2020/gif/326147/1589508133558-632d3521-daa1-45a9-bf65-5370288cf3a4.gif#align=left&display=inline&height=202&margin=%5Bobject%20Object%5D&name=189.gif&originHeight=202&originWidth=397&size=112571&status=done&style=none&width=397)
import 'package:flutter/material.dart';
class CustomLimitedBox extends StatefulWidget {
@override
_CustomLimitedBoxState createState() => _CustomLimitedBoxState();
}
class _CustomLimitedBoxState extends State<CustomLimitedBox> {
var _text = '';
@override
Widget build(BuildContext context) {
var child = Container(
alignment: Alignment.center,
color: Colors.cyanAccent,
width: 50,
height: 50,
child: Text("Static"),
);
var box = LimitedBox(
maxHeight: 60,
maxWidth: 100,
child: Container(color: Colors.orange, child: Text(_text)),
);
return Column(
children: <Widget>[
Container(
color: Colors.grey.withAlpha(22),
width: 300,
height: 100,
child: Row(
children: <Widget>[child, UnconstrainedBox(child: box), child],
),
),
_buildInput()
],
);
}
Widget _buildInput() {
return Padding(
padding: const EdgeInsets.all(18.0),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: '请输入',
),
onChanged: (v) {
setState(() {
_text = v;
});
},
),
);
}
}