如何解决混合TextField和Text
解决方法
如果只想使用TextField
进行此查看,则可能要考虑两件事:
- Column class用于维护下一行中的项目
- Row class用于水平延续项目
代码如下:
请注意: TextField
正在工作。因此,您可以使用它,但请务必阅读用法。它仅用于表示,但如果要捕获TextEditingController
TextField
Column(
mainAxisSize: MainAxisSize.min,crossAxisAlignment: CrossAxisAlignment.start,children: [
// top layer
Row(
mainAxisSize: MainAxisSize.min,mainAxisAlignment: MainAxisAlignment.start,children: [
Text("<body",style: TextStyle(color: Colors.blue[900])),SizedBox(width: 8.0),Text("style",style: TextStyle(color: Colors.greenAccent)),Text("=",style: TextStyle(color: Colors.grey))
]
),// Middle layer,for next line
Row(
mainAxisSize: MainAxisSize.min,children: [
Text("''",style: TextStyle(color: Colors.orange)),SizedBox(width: 80.0,child: TextField()),// this is textfield
Text(":yellow;",// Middle layer part 2,children: [
Text("background-color:",style: TextStyle(color: Colors.indigo)),Text("black;",style: TextStyle(color: Colors.grey)),Text("''>",style: TextStyle(color: Colors.orange))
]
),// for next line
Row(
mainAxisSize: MainAxisSize.min,children: [
Text("hi :)",style: TextStyle(color: Colors.grey[500]))
]
),// last line
Row(
mainAxisSize: MainAxisSize.min,children: [
Text("</___________>",]
)
这可能对您来说很长,但这将达到结果的目的。
,我通过使用WidgetSpan
获得解决方案所以解决方案是这样的:
Text.rich(
TextSpan(
children: <InlineSpan>[
TextSpan(text: '<body ',style: TextStyle(
color: Colors.blue,fontSize: 24
),),TextSpan(text: 'style=\n"',style: TextStyle(
color: Colors.teal,WidgetSpan(
child: SizedBox(
width: 30,height: 30,child: TextField()
),TextSpan(text: ':yellow;',style: TextStyle(
color: Colors.grey,TextSpan(text: '\nbackground-color:',style: TextStyle(
color: Colors.purple,TextSpan(text: 'black;',TextSpan(text: '">',style: TextStyle(
color: Colors.teal,TextSpan(text: '\nhi :)',TextSpan(text: '\n</',TextSpan(text: '>',],)
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。