gpt4 book ai didi

flutter - 如何在 Flutter 中为 Text Widget 添加自定义删除线

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

我正在寻找一种方法来向如下所示的文本小部件添加自定义删除线

enter image description here

我查看了文本样式 API,但找不到任何自定义删除线图形的选项。

style: TextStyle(decoration: TextDecoration.lineThrough),

最佳答案

作为一个选项

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: StrikeThroughWidget(
child: Text('Apple Juice', style: TextStyle(fontSize: 30)),
),
),
),
);
}
}

class StrikeThroughWidget extends StatelessWidget {
final Widget _child;

StrikeThroughWidget({Key key, @required Widget child})
: this._child = child,
super(key: key);

@override
Widget build(BuildContext context) {
return Container(
child: _child,
padding: EdgeInsets.symmetric(horizontal: 8), // this line is optional to make strikethrough effect outside a text
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('graphics/strikethrough.png'), fit: BoxFit.fitWidth),
),
);
}
}

结果 enter image description here

和删除线图像 enter image description here

关于flutter - 如何在 Flutter 中为 Text Widget 添加自定义删除线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56141301/

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