flutter - 在列小部件内的特定位置对齐行项目

标签 flutter dart flutter-layout

难以将行小部件内的行项目定位在特定边缘位置(如此图像):

enter image description here

Padding(
    padding: const EdgeInsets.all(10.0),
    child: Column(
      children: <Widget>[
        values('Date', ': ${DateFormat('MMM dd, yyyy, hh:mm a').format(DateTime.parse(date))}', false),
        values('Description', ': $description', false),
      ],
    ),
  ),



Widget values(String title, String value, bool isAmount) {
    return Row(
      children: <Widget>[
        Text(
          title,
          style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey),
        ),
        Spacer(),
        Text(
          value,
          style: TextStyle(
            color: isAmount ? Color(0xFF34B3C1) : Colors.black87,
          ),
        ),
        Spacer(),
      ],
    );
  }

最佳答案

使用扩展后的 flex 来实现,

  Widget values(String title, String value, bool isAmount) {
    return Row(
      children: <Widget>[
        Expanded(
          flex: 3,
          child: Text(
            title,
            style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey),
          ),
        ),
        Spacer(),
        Expanded(
          flex: 7,
          child: Text(
            value,
            style: TextStyle(
              color: isAmount ? Color(0xFF34B3C1) : Colors.black87,
            ),
          ),
        ),
        Spacer(),
      ],
    );
  }

关于flutter - 在列小部件内的特定位置对齐行项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58948539/

相关文章:

flutter - ListView 生成器创建列表项的副本

dart - Angular2 Dart : Dividing a project in packages does not allow to reuse base components with modified providers

flutter - 如何在Flutter中扫描二维码后自动打开链接而不点击某个按钮

http - 如何在Flutter中使用DIO将多个文件,文件列表发布到服务器

android - 使用google_maps_autocomplete后Flutter无法运行

dart - NetworkImage抖动- token 已过期

dart - 用多个引用查询。 Firestore- flutter

dart - Flutter 在 RaisedButton 上设置状态 onPressed

android - 步进器的自定义按钮设计

flutter - 在Dart中管理异常