layout - Flutter 中的基本对齐文本和虚线

标签 layout flutter styling

我正在尝试为我的 Flutter 应用创建这样的东西:

enter image description here

现在我已经成功地得到了一行文字,一条虚线和更大的文字,物有所值。我似乎无法解决的最后一个问题是消除不同大小文本中的可变大小差距。

enter image description here

[编辑] 我的意思是让所有内容都对齐在同一条红线上:

enter image description here

查看this answer我想我可以做同样的事情并将所有文本放在定位的堆栈中。然而,这破坏了我的布局,给我这个错误:

I/flutter (26439): The following assertion was thrown during performLayout():
I/flutter (26439): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I/flutter (26439): When a column is in a parent that does not provide a finite height constraint, for example if it is
I/flutter (26439): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
I/flutter (26439): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter (26439): space in the vertical direction.
I/flutter (26439): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter (26439): cannot simultaneously expand to fit its parent.
I/flutter (26439): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter (26439): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter (26439): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter (26439): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter (26439): constraints provided by the parent.
I/flutter (26439): The affected RenderFlex is:
I/flutter (26439):   RenderFlex#c7fb1 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26439): The creator information is set to:
I/flutter (26439):   Column ← Expanded ← Row ← Column ← Padding ← RepaintBoundary-[<0>] ← IndexedSemantics ←
I/flutter (26439):   NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← SliverList ←
I/flutter (26439):   MediaQuery ← ⋯
I/flutter (26439): See also: https://flutter.dev/layout/

这是我的相关代码:

Row(
  crossAxisAlignment: CrossAxisAlignment.end,
  children: <Widget>[
    Text('Salary Cap'),
    // Stack( // Will cause error
    //   fit: StackFit.expand,
    //   children: <Widget>[
    //     Positioned(
    //       top: 0,
    //       left: 0,
    //       width: 200,
    //       child: Text('Salary Cap'),
    //     ),
    //   ],
    // ),
    Expanded(
      child: Container(
        width: double.infinity,
        child: CustomPaint(painter: LineDashedPainter()),
      ),
    ),
    RichText(
      text: TextSpan(
        children: <TextSpan>[
          TextSpan(text: '\$'),
          TextSpan(
            text:
                '${oCcy.format(salaryLimit)}',
            style: Theme.of(context).textTheme.display1,
          ),
        ],
      ),
    ),
  ],
),

有什么建议吗?

最佳答案

你可以使用这两行

crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.ideographic,

关于layout - Flutter 中的基本对齐文本和虚线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56170779/

相关文章:

android - 选择器不适用于布局和 ImageView

android - 如何在单个 RecyclerView 中实现 RecyclerView?

flutter - 如何将 void 函数放入单独的 dart 文件的单独页面中

visual-studio - Visual Studio 窗口布局预设

c++ - 如何调整 QVBoxLayout 的大小以填充没有空格的表单?

firebase - 在android studio中添加firebase到flutter时出错: Plugin project :firebase_core_web not found. 请更新settings.gradle

dart - GPS是否激活 - flutter

WPF - 如何设置菜单控件的样式以删除左边距?

html - PC 中的字体可以在在线网站中使用吗?

CSS 样式不适用于文本框