Flutter IntrinsicHeight 自适应组件大小
  VAPgPnIrcYmH 2023年11月02日 53 0


1 简说

  • IntrinsicHeight 是Flutter 中的一个 Widget
  • IntrinsicHeight 是一种根据子 Widget 的固有高度来调整 子Widget 尺寸的小部件。

2 Row 中的两个子Widget 无限填充

class InstrinsicPage01 extends StatelessWidget{

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("测试"),),
body: buildRow(),
);
}

buildRow() {
return Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width: 150,
height: 100,
color: Colors.teal,
),
Container(
width: 150,
height: 200,
color: Colors.red,
)
],
);
}
}

3 Row 中的两个子Widget 高度为 200

class InstrinsicPage01 extends StatelessWidget{

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("测试"),),
body: buildIns(),
);
}
buildIns() {
return IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width: 150,
height: 100,
color: Colors.teal,
),
Container(
width: 150,
height: 200,
color: Colors.red,
)
],
),
);
}
}

4 Row 中的两个子Widget 高度为 400

buildIns() {
return SizedBox(
height: 400,
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width: 150,
height: 100,
color: Colors.teal,
),
Container(
width: 150,
height: 200,
color: Colors.red,
)
],
),
);
}


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  b1UHV4WKBb2S   2023年11月13日   40   0   0 ide抗锯齿
  iD7FikcuyaVi   2023年11月30日   26   0   0 MacWindowsandroid
  b1UHV4WKBb2S   2023年11月13日   37   0   0 裁剪ideflutter
  b1UHV4WKBb2S   2023年11月13日   29   0   0 flutterDart
  zSWNgACtCQuP   2023年11月13日   32   0   0 ide
VAPgPnIrcYmH