作为Flutter 翼的初学者,我正在努力实现绿色微件上下两侧的动态调整,以及右侧微件部件的上下两侧的动态调整.此外,我正在寻求如何解决图像中显示的溢出问题的指导.

先谢谢你

[image](https://i.stack.imgur.com/nF380.jpg)

我已经将我的代码包含在下面,并try 了各种方法来实现所需的设计.然而,我并没有成功地完成它.有没有人能给我详细解释一下如何实现这个设计?

import 'package:flutter/material.dart';

class Test extends StatelessWidget {
  const IomHistory2({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return history();
  }

  Widget history() {
    return Container(
      color: Colors.lightBlue,
      child: Row(
        //crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          leftContainer("1", Colors.green),
          Container(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                rightContainer(
                    "Forgot to attendance punch, i was in the office from 8.30 to 6.20",
                    null,
                    false),
                rightContainer("23/01/2023-23/01/2023", Icons.date_range, true),
                rightContainer("08:30-18:20", Icons.access_time, true),
                rightContainer("Accepted", Icons.done, true),
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget leftContainer(String totalDays, Color color) {
    return Container(
      padding: const EdgeInsets.only(top: 16, bottom: 16, left: 8, right: 8),
      decoration: BoxDecoration(
          color: color,
          borderRadius: const BorderRadius.only(
              topLeft: Radius.zero,
              topRight: Radius.circular(8.0),
              bottomLeft: Radius.zero,
              bottomRight: Radius.circular(8.0))),
      child: Column(
        //crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisSize: MainAxisSize.min,
        children: [
          customTextLeftContainer(totalDays),
          customTextLeftContainer("Day"),
        ],
      ),
    );
  }

  Widget rightContainer(String value, IconData? iconData, bool iconShowed) {
    return Container(
      margin: const EdgeInsets.only(left: 8),
      child: Row(
        children: [
          iconShowed ? Icon(size: 14, iconData) : Container(),
          customTextRightContainer(value, iconShowed)
        ],
      ),
    );
  }

  Widget customTextLeftContainer(String value) {
    return Text(value,
        style: const TextStyle(
            fontFamily: 'Rubik', fontSize: 12, fontWeight: FontWeight.bold));
  }

  Widget customTextRightContainer(String value, bool iconShowed) {
    return Container(
      margin: iconShowed
          ? const EdgeInsets.only(left: 8)
          : const EdgeInsets.only(left: 0),
      child: Text(
        value,
        style: const TextStyle(
          fontFamily: 'Rubik',
        ),
      ),
    );
  }

}

100

enter image description here

推荐答案

您可以用Intrinsic个Widget包装Row,然后使用crossAxisAlignment: CrossAxisAlignment.stretch.

并在必要时使用Expanded小工具.

Output:

enter image description here

Complete code:


  Widget history() {
    return Container(
      margin: EdgeInsets.only(top: 32),
      color: Colors.lightBlue,
      child: IntrinsicHeight(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            leftContainer("1", Colors.green),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                // mainAxisSize: MainAxisSize.min,
                children: [
                  rightContainer(
                      "Forgot to attendance punch, i was in the office from 8.30 to 6.20",
                      null,
                      false),
                  rightContainer(
                      "23/01/2023-23/01/2023", Icons.date_range, true),
                  rightContainer("08:30-18:20", Icons.access_time, true),
                  rightContainer("Accepted", Icons.done, true),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget leftContainer(String totalDays, Color color) {
    return Container(
      padding: const EdgeInsets.only(top: 16, bottom: 16, left: 8, right: 8),
      decoration: BoxDecoration(
          color: color,
          borderRadius: const BorderRadius.only(
              topLeft: Radius.zero,
              topRight: Radius.circular(8.0),
              bottomLeft: Radius.zero,
              bottomRight: Radius.circular(8.0))),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          customTextLeftContainer(totalDays),
          customTextLeftContainer("Day"),
        ],
      ),
    );
  }

  Widget rightContainer(String value, IconData? iconData, bool iconShowed) {
    return Container(
      margin: const EdgeInsets.only(left: 8),
      child: Row(
        children: [
          iconShowed ? Icon(size: 14, iconData) : Container(),
          Expanded(child: customTextRightContainer(value, iconShowed))
        ],
      ),
    );
  }

  Widget customTextLeftContainer(String value) {
    return Text(value,
        style: const TextStyle(
            fontFamily: 'Rubik', fontSize: 12, fontWeight: FontWeight.bold));
  }

  Widget customTextRightContainer(String value, bool iconShowed) {
    return Container(
      margin: iconShowed
          ? const EdgeInsets.only(left: 8)
          : const EdgeInsets.only(left: 0),
      child: Text(
        value,
        style: const TextStyle(
          fontFamily: 'Rubik',
        ),
      ),
    );
  }
}

Flutter相关问答推荐

Cupertino Buttino SheetAction on按下可触发加载指示器,然后勾选并延迟

如何在容器中移动图标按钮?

为什么他们实例化类,然后丢弃该实例?

我不能通过第5步了解Flutter 翼Firebase教程

Flutter 应用程序中的Firebase实时数据库中的orderByChild()不适用于我

如何实现Flutter 梳理机图像的小量移动

上传的图像不能在FireBase中预览.S档案类型为空白,摆动

dart /长笛中的返回早期模式和拆分方法

如何使 dart 函数变得通用?

Flutter Xcode 15 错误(Xcode):DT_TOOLCHAIN_DIR 无法用于判断 LIBRARY_SEARCH_PATHS

如何在 Dart/Flutter 中克隆 Future

Dart 和 flutter 错误无法在您的 PATH 中找到 git

我怎样才能消除我的 Column 子元素之间的差距?

如何在两个不同的路由(屏幕)之间正确设置 BlocProvider?

在 Flutter 中将提取的 Listview.builder 与两个列表一起使用

Flutter Widget 测试:无法使用 find.byWidget() 找到小部件

如何在 flutter 中更改日期 Select 器 colored颜色 ?

Flutter - 检测手指何时进入容器

参数类型Future>不能分配给参数类型Future>?

用于空值 FirebaseFirestore 的空值判断运算符