Cretezy / flutter_linkify

Turns text URLs and emails into clickable inline links in text for Flutter
https://pub.dartlang.org/packages/flutter_linkify
MIT License
263 stars 99 forks source link

TextStyle changes from parents are lost #27

Closed Erfa closed 4 years ago

Erfa commented 4 years ago

I noticed that if you have a TextStyle as a parent Widget to Linkify, that styling is overriden by whatever style you set in Linkify.

Here's an example:

DefaultTextStyle.merge(
  style: TextStyle(decoration: TextDecoration.lineThrough),
  child: Linkify(
    text: 'Testing https://github.com',
  ),
)

This will correctly identify the link, but it will lose the TextDecoration.lineThrough defined by the parent. Seems like the desired behavior would be to merge them? I'm fairly new to Flutter so I'm not sure if it's possible.

Cretezy commented 4 years ago

This is due to DefaultTextStyle not overriding body1.

Doing this does fix it:

Theme(
  data: ThemeData(
    textTheme: TextTheme(
      body1: TextStyle(decoration: TextDecoration.lineThrough),
    ),
  ),
  child: Linkify(
    text: 'Testing https://github.com',
  ),
)

Doing does the same but is much simpler:

Linkify(
  text: 'Testing https://github.com',
  style: TextStyle(decoration: TextDecoration.lineThrough),
)

image

To change the link to also have lineThrough, pass it in the linkStyle:

Linkify(
  text: 'Testing https://github.com',
  style: TextStyle(decoration: TextDecoration.lineThrough),
  linkStyle: TextStyle(
    decoration: TextDecoration.combine(
      [TextDecoration.lineThrough, TextDecoration.underline],
    ),
  ),
)

image