Package selection guidance compiled from public package information, community data, and project usage.
ExpandableRichText is a Flutter widget that displays text with a limited initial height, allowing users to expand and view the full content. It supports rich text formatting and includes built-in handling for clickable @mentions, making it ideal for chat interfaces or long-form content previews. The widget is designed for smooth user interaction across multiple platforms, including mobile, web, and desktop. It integrates seamlessly into cards or expansion tiles where space efficiency and interactivity are key.
Use cases
Chat message previews
Long-form content summaries
User comment sections
Interactive rich text displays
Dynamic text expansion in lists
Social media-style post views
Key features
Limited initial line display
Auto-expansion on tap
Clickable @mentions
Rich text support
Cross-platform compatibility
Customizable expand/collapse behavior
Suitable for
Developers building chat apps
UI designers needing compact text components
Apps with dynamic content length
Projects requiring interactive text elements
Teams using rich text with mentions
Multi-platform Flutter applications
Considerations
May require additional styling for complex layouts
Performance impact with very long texts
Needs careful handling of nested widgets
Limited to text-based interactions
Not suitable for non-interactive content
Requires proper context for mention parsing
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
Expandable RichText
A text widget that you can use to initially only show a defined number of lines of a probably long
text. It also supports clickable @mention, #hashtag, and hyperlinks. You can define styles
for @mention, #hashtag, and hyperlinks and apply custom styles on text segments.
Features
Collapse and Expand text
Configure text to show to Expand text (expandText) and to Collapse text (collapseText)
Control whether the ellipsis (showEllipsis) is part of the Expand/Collapse text
Expand and Collapse animation
Callback for expanded changed event (onExpandedChanged)
Apply different style at @mention, #hashtag, hyperlinks and text segments
Handle click on @mention, #hashtag, hyperlinks and text segments
Widgetbuild(BuildContext context) {
returnExpandableRichText(
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
expandText: 'show more',
collapseText: 'show less',
maxLines: 2,
linkColor: Colors.blue,
);
}
If text have @mention, #hashtag, hyperlinks and text segments:
Widgetbuild(BuildContext context) {
returnExpandableRichText(
"Lorem ipsum dolor sit amet..., #consetetur @sadipscing elitr, <tag1>I am Admin1</tag1> tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <tag2>I am employee1</tag2> At vero eos et accusam et justo duo dolores et ea rebum Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum www.galley.com dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, <tag1>I am Admin2</tag1> diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. <tag2>I am employee2</tag2> Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
expandText: 'show more',
collapseText: 'show less',
maxLines: 1,
linkColor: Colors.blue,
mentionStyle: constTextStyle(
color: Colors.blueAccent, fontSize: 16, fontWeight: FontWeight.bold),
hashtagStyle: constTextStyle(
fontSize: 16, color: Colors.white, backgroundColor: Colors.black87),
urlStyle: constTextStyle(
color: Colors.lightBlueAccent, decoration: TextDecoration.underline),
customTagStyle: constTextStyle(fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
fontSize: 16,
color: Colors.white,
backgroundColor: Colors.lightBlueAccent,
decoration: TextDecoration.underline)
);
}
Advance Usage
Widgetbuild(BuildContext context) {
returnExpandableRichText(
"Lorem ipsum dolor sit amet..., #consetetur @sadipscing elitr, <tag1>I am Admin1</tag1> tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <tag2>I am employee1</tag2> At vero eos et accusam et justo duo dolores et ea rebum Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum www.galley.com dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, <tag1>I am Admin2</tag1> diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. <tag2>I am employee2</tag2> Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
expandText: 'show more',
collapseText: 'show less',
expanded: false,
onExpandedChanged: (flag) => {},
toggleTextColor: Colors.black,
showEllipsis: true,
toggleTextStyle: constTextStyle(
fontSize: 12, color: Colors.blue, decoration: TextDecoration.underline),
urlStyle: constTextStyle(color: Colors.lightBlueAccent, decoration: TextDecoration.underline),
onUrlTap: (url) => {},
hashtagStyle: constTextStyle(
fontSize: 16, color: Colors.white, backgroundColor: Colors.black87),
mentionStyle: constTextStyle(
color: Colors.blueAccent, fontSize: 16, fontWeight: FontWeight.bold),
onMentionTap: (mention) => {},
customTagStyle: constTextStyle(fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
fontSize: 16,
color: Colors.white,
backgroundColor: Colors.lightBlueAccent,
decoration: TextDecoration.underline),
onCustomTagTap: (tag) => {},
expandOnTextTap: true,
collapseOnTextTap: true,
style: constTextStyle(color: Colors.black, fontSize: 24),
textDirection: TextDirection.ltr,
textAlign: TextAlign.start,
textScaleFactor: 1.0,
maxLines: 2,
animation: true,
animationDuration: constDuration(milliseconds: 200),
animationCurve: Curves.fastLinearToSlowEaseIn,
);
}
Bugs and feature requests
Have a bug or a feature request? Please first search for existing and closed issues. If your problem
or idea is not addressed
yet, please open a new issue.