ExpandableRichText는 초기 높이가 제한된 텍스트를 표시하는 Flutter 위젯으로, 사용자가 전체 내용을 확장하여 볼 수 있도록 합니다. 풍부한 텍스트 형식을 지원하며, 클릭 가능한 @멘션을 내장된 방식으로 처리하여 채팅 인터페이스나 긴 형식의 콘텐츠 미리보기에 적합합니다. 이 위젯은 모바일, 웹, 데스크톱 등 여러 플랫폼에서 원활한 사용자 상호작용을 위해 설계되었으며, 공간 효율성과 상호작용이 중요한 카드 또는 확장 타일에 자연스럽게 통합됩니다.
사용 사례
채팅 메시지 미리보기
장문 콘텐츠 요약
사용자 댓글 섹션
인터랙티브한 리치 텍스트 표시
목록 내 동적 텍스트 확장
소셜 미디어 스타일 게시물 조회수
주요 기능
제한된 초기 줄 표시
터치 시 자동 확장
클릭 가능한 @멘션
리치 텍스트 지원
크로스 플랫폼 호환성
사용자 정의 가능한 전개/접기 동작
적합한 대상
채팅 앱을 개발하는 개발자
작은 텍스트 컴포넌트가 필요한 UI 디자이너
동적 콘텐츠 길이를 가진 앱
상호작용 텍스트 요소가 필요한 프로젝트
멘션을 포함한 풍부한 텍스트를 사용하는 팀
다중 플랫폼 Flutter 애플리케이션
고려 사항
복잡한 레이아웃을 위해 추가 스타일링이 필요할 수 있습니다
매우 긴 텍스트로 인한 성능 영향
중첩된 위젯을 신중하게 다뤄야 합니다
텍스트 기반 상호작용에 제한됨
상호작용이 없는 콘텐츠에 적합하지 않습니다
참조 분석을 위해서는 적절한 컨텍스트가 필요합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
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.