如何修改Flutter中TextDecoration删除线的颜色?
修改Flutter Text组件删除线颜色的方法
先看你给出的原始代码:
Text( text = "Told lee he'd be a millionaire", color = Color.White, textDecoration = TextDecoration.LineThrough )
这段代码运行后,文字为白色,但删除线颜色会和文字颜色保持一致,无法单独区分。
你想要实现删除线与文字颜色不同的效果,在Flutter中可以通过TextStyle的decorationColor属性来实现,修改后的代码如下:
Text( "Told lee he'd be a millionaire", style: TextStyle( color: Colors.white, decoration: TextDecoration.lineThrough, decorationColor: Colors.red, // 自定义删除线颜色 decorationStyle: TextDecorationStyle.solid, // 可选,设置删除线样式,比如实线、虚线等 ), )
核心逻辑:启用删除线的同时,通过decorationColor单独指定删除线的颜色,就能让文字和删除线呈现不同色彩,满足你的需求。
内容的提问来源于stack exchange,提问作者Kun.tito
相关产品推荐
相关产品推荐

