gpt4 book ai didi

dart - 在 Flutter 中的组件顶部叠加一条线

转载 作者:IT王子 更新时间:2023-10-29 06:36:17 26 4
gpt4 key购买 nike

我的一个组件中有以下布局,我想在上面放一行:example image from mockup

这是我当前的代码,并且已经在 Flutter 的 API 文档中搜索了一段时间,但没有找到适合实现它的东西。

new Row(
children: <Widget>[
new Expanded(
child: const Text("Some text"),
),
const Text("Some other text"),
],
)

任何指示或想法如何做到这一点?

最佳答案

好的。通过使用自定义 Decoration 让它工作。
这是我的代码:

class StrikeThroughDecoration extends Decoration {
@override
BoxPainter createBoxPainter([VoidCallback onChanged]) {
return new _StrikeThroughPainter();
}
}

class _StrikeThroughPainter extends BoxPainter {
@override
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
final paint = new Paint()
..strokeWidth = 1.0
..color = Colors.black
..style = PaintingStyle.fill;

final rect = offset & configuration.size;
canvas.drawLine(new Offset(rect.left, rect.top + rect.height / 2), new Offset(rect.right, rect.top + rect.height / 2), paint);
canvas.restore();
}
}

在我的组件中这样使用:

new Container(
foregroundDecoration: new StrikeThroughDecoration(),
child: new Row(
children: <Widget>[
new Expanded(
child: const Text("Some text"),
),
const Text("Some other text"),
],
)
)

关于dart - 在 Flutter 中的组件顶部叠加一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46132737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com