Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make text selectable #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions lib/substring_highlight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class SubstringHighlight extends StatelessWidget {
),
this.wordDelimiters = ' .,;?!<>[]~`@#\$%^&*()+-=|\/_',
this.words =
false // default is to match substrings (hence the package name!)

false, // default is to match substrings (hence the package name!)
this.selectable = false
})
: assert(term != null || terms != null);

Expand Down Expand Up @@ -64,6 +64,9 @@ class SubstringHighlight extends StatelessWidget {

/// If true then match complete words only (instead of characters or substrings within words). This feature is in ALPHA... use 'words' AT YOUR OWN RISK!!!
final bool words;

/// If true then text is selectable
final bool selectable;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -158,11 +161,17 @@ class SubstringHighlight extends StatelessWidget {
}
}

return RichText(
maxLines: maxLines,
overflow: overflow,
text: TextSpan(children: children, style: textStyle),
textAlign: textAlign,
textScaleFactor: MediaQuery.of(context).textScaleFactor);
return selectable
? SelectableText.rich(TextSpan(children: children, style: textStyle),
maxLines: maxLines,
// overflow: overflow,
textAlign: textAlign,
textScaleFactor: MediaQuery.of(context).textScaleFactor)
: RichText(
maxLines: maxLines,
overflow: overflow,
text: TextSpan(children: children, style: textStyle),
textAlign: textAlign,
textScaleFactor: MediaQuery.of(context).textScaleFactor);
}
}