• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Flutter IntrinsicHeight 自适应组件大小

武飞扬头像
早起的年轻人
帮助1

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,
          )
        ],
      ),
    );
  }
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgakkgf
系列文章
更多 icon
同类精品
更多 icon
继续加载