我没有在flutter中使用过canvas,但我认为像图像中的编辑文本框可以通过canvas来实现。背景随着文本长度而扩展,如果一行中的文本长度为 0,则没有背景。
如果您有任何代码或建议可以这样做,请提供帮助。
这里是代码:
class TextFieldTest extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: SingleChildScrollView(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 50),
child: TextField(
maxLines: 10,
keyboardType: TextInputType.multiline,
textAlign: TextAlign.center,
style: TextStyle(
wordSpacing: 5,
height: 2,
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 26,
background: Paint()
..color = Colors.blue
..style = PaintingStyle.stroke
..strokeWidth = 35
..strokeJoin = StrokeJoin.round,
),
),
),
),
);
}
}
borderWidth 应大于 fontSize,以便按您选择的颜色填充所有文本。
尝试使用它,以便您最终得到更准确的结果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)