我通过使用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,
fontSize: 24
),),
WidgetSpan(
child: SizedBox(
width: 30,
height: 30,
child: TextField()
),
),
TextSpan(text: ':yellow;',style: TextStyle(
color: Colors.grey,
fontSize: 24
),),
TextSpan(text: '\nbackground-color:',style: TextStyle(
color: Colors.purple,
fontSize: 24
),),
TextSpan(text: 'black;',style: TextStyle(
color: Colors.grey,
fontSize: 24
),),
TextSpan(text: '">',style: TextStyle(
color: Colors.teal,
fontSize: 24
),),
TextSpan(text: '\nhi :)',style: TextStyle(
color: Colors.grey,
fontSize: 24
),),
TextSpan(text: '\n</',style: TextStyle(
color: Colors.grey,
fontSize: 24
),),
WidgetSpan(
child: SizedBox(
width: 30,
height: 30,
child: TextField()
),
),
TextSpan(text: '>',style: TextStyle(
color: Colors.grey,
fontSize: 24
),),
],
)
)