搜索插件、代码仓与 APP 分类

插件详情v1.0.7

expandable_richtext

一个文本小部件,可用于最初仅显示可能很长的文本中的指定行数。它还支持可点击的 @提及。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1110
喜欢数
35
Pub 分数
160

安装插件

flutter pub add expandable_richtext

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

ExpandableRichText 是一个 Flutter 小部件,用于显示具有初始高度限制的文本,允许用户展开以查看完整内容。它支持富文本格式,并内置了对可点击 @提及 的处理,非常适合聊天界面或长篇内容预览。该小部件专为跨多个平台(包括移动设备、网页和桌面)的流畅用户体验而设计。它可无缝集成到卡片或展开式瓷砖中,适用于空间效率和交互性至关重要的场景。

适合场景

  • 聊天消息预览
  • 长篇内容摘要
  • 用户评论区
  • 交互式富文本显示
  • 列表中的动态文本扩展
  • 社交媒体风格的帖子浏览量

主要特点

  • 有限的初始行显示
  • 点击自动展开
  • 可点击的 @提及
  • 富文本支持
  • 跨平台兼容性
  • 可自定义的展开/折叠行为

适合对象

  • 开发聊天应用的开发者
  • UI 设计师需要紧凑的文本组件
  • 动态内容长度的应用程序
  • 需要交互式文本元素的项目
  • 使用丰富文本和提及功能的团队
  • 跨平台 Flutter 应用

使用建议

  • 可能需要额外的样式设置以适应复杂布局
  • 长文本带来的性能影响
  • 需要仔细处理嵌套的组件
  • 限于文本交互
  • 不适合非交互式内容
  • 需要正确的上下文以进行提及解析

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Expandable RichText

pub package license

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
  • Programmatically expand and collapse text

Example with maxLines=1

Getting started

Add this to your package's pubspec.yaml file:

dependencies:
  expandable_richtext: 1.0.7

Next, import the package into your dart code:

import 'package:expandable_rich_text/expandable_richtext.dart';
Usage

If text exceeds two lines:

Widget build(BuildContext context) {
  return ExpandableRichText(
    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:

Widget build(BuildContext context) {
  return ExpandableRichText(
      "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: const TextStyle(
          color: Colors.blueAccent, fontSize: 16, fontWeight: FontWeight.bold),
      hashtagStyle: const TextStyle(
          fontSize: 16, color: Colors.white, backgroundColor: Colors.black87),
      urlStyle: const TextStyle(
          color: Colors.lightBlueAccent, decoration: TextDecoration.underline),
      customTagStyle: const TextStyle(fontWeight: FontWeight.bold,
          fontStyle: FontStyle.italic,
          fontSize: 16,
          color: Colors.white,
          backgroundColor: Colors.lightBlueAccent,
          decoration: TextDecoration.underline)
  );
}
Advance Usage
Widget build(BuildContext context) {
  return ExpandableRichText(
    "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: const TextStyle(
        fontSize: 12, color: Colors.blue, decoration: TextDecoration.underline),
    urlStyle: const TextStyle(color: Colors.lightBlueAccent, decoration: TextDecoration.underline),
    onUrlTap: (url) => {},
    hashtagStyle: const TextStyle(
        fontSize: 16, color: Colors.white, backgroundColor: Colors.black87),
    mentionStyle: const TextStyle(
        color: Colors.blueAccent, fontSize: 16, fontWeight: FontWeight.bold),
    onMentionTap: (mention) => {},
    customTagStyle: const TextStyle(fontWeight: FontWeight.bold,
        fontStyle: FontStyle.italic,
        fontSize: 16,
        color: Colors.white,
        backgroundColor: Colors.lightBlueAccent,
        decoration: TextDecoration.underline),
    onCustomTagTap: (tag) => {},
    expandOnTextTap: true,
    collapseOnTextTap: true,
    style: const TextStyle(color: Colors.black, fontSize: 24),
    textDirection: TextDirection.ltr,
    textAlign: TextAlign.start,
    textScaleFactor: 1.0,
    maxLines: 2,
    animation: true,
    animationDuration: const Duration(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.

Author

DevCrew I/O

Connect with Us:

devcrew.io mycompany devcrew.io devcrew.io DevCrew-io

Contributing

Contributions, issues, and feature requests are welcome!

Show your Support

Give a star if this project helped you.

Copyright & License

Code copyright 2023 DevCrew I/O. Code released under the MIT license.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。