我想显示一个文本小部件内单独 View 的链接
我尝试在两者之间添加两个文本小部件和一个平面按钮,但未按预期显示
我希望它看起来像
<p>This is a <a href="#">sample</a> text</p>
这就是我尝试过的
Column(
children: [
Text('This is a '),
FlatButton(
onPress: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>View()))
}
child: Text('sample')
),
Text(' text')
]
)
最佳答案
TapGestureRecognizer _recognizer;
@override
void initState() {
super.initState();
_recognizer = TapGestureRecognizer()..onTap = (){
print("tapped");
};
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: 'This is a '),
TextSpan(text: 'sample', style: TextStyle(fontWeight: FontWeight.bold), recognizer: _recognizer),
TextSpan(text: ' text'),
],
),
),
),
);
}
关于flutter - 在文本小部件中向导航器添加链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57269740/