Reputation: 351
I want to show a link to seperate view inside a text widget
I tried adding Two Text Widgets and a flat button in between but it doesnt show as expected
How I want it to look like
<p>This is a <a href="#">sample</a> text</p>
This is what i tried
Column(
children: [
Text('This is a '),
FlatButton(
onPress: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>View()))
}
child: Text('sample')
),
Text(' text')
]
)
Upvotes: 1
Views: 987
Reputation: 267604
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'),
],
),
),
),
);
}
Upvotes: 2