For example :
String desc = "<bold>Hello<bold> World";
new Text(desc);
This is how you can achieve a 'Connecting' String in Flutter. In Example, there is a Text Widget which is print your String and it takes text style property to give italic font size. I hope you will get the idea, if this will help you then give the right tick and flag up, Happy Fluttering.
But in Flutter, if you want add some extra space around a widget, then you wrap it in a Padding widget. Now to add padding, wrap the Text widget with a Padding widget. In Android Studio this can be accomplished by placing your cursor on the widget and pressing Option+Enter (or Alt+Enter in Windows/Linux).
You can use the flutter_html_view package for that.
String html = '<bold>Hello<bold> World';
new HtmlTextView(data: html);
If you just want different styles you can use a RichText
widget with TextSpans
like this.
new RichText( text: new TextSpan(text: 'Hello ', style: DefaultTextStyle.of(context).style, children:
<TextSpan>[
new TextSpan(text: 'bold', style: new TextStyle(fontWeight: FontWeight.bold)),
new TextSpan(text: ' world!'),
], ), )
You can have a RichText widget, which can take TextSpan as its child. TextSpan can then take multiple TextSpan as its children, and each TextSpan can have its own styles and gesture detectors. An example of how to crate "read more" privacy statement with onTap gesture detector is below. This will give an output as shown below and when clicked on "Read" the app will be routed to '/privacy' page.
class _LoginViewState extends State<LoginView> {
TapGestureRecognizer _routeToPrivacy;
@override
void initState() {
super.initState();
_routeToPrivacy= TapGestureRecognizer()..onTap = routeToPrivacy;
}
void routeToPrivacy() {
Navigator.pushNamed(context, '/privacy');
}
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Container(
width: 200,
child: Column(
RichText(
text: TextSpan(
style: TextStyle(
color: Colors.blue.shade900,
fontFamily: GoogleFonts.lato().fontFamily),
children: [
TextSpan(
text: 'By signing up you accepts our privacy policy. ',
),
TextSpan(
recognizer: _routeToPrivacy,
text: "Read",
style: TextStyle(
color: Colors.red.shade500,
fontWeight: FontWeight.bold))
],
),
),
],
),
),
),
);
}
StyledText widget can be used for this.
StyledText(text:desc,
styles: { 'bold': ActionTextStyle(fontWeight: FontWeight.bold)},
);
You can use simple_rich_text package.
SimpleRichText("*Hello* World")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With