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

GitHub 代码仓fweinaug/expandable_text

可展开文本

带有可展开文本控件的 Flutter 插件

可展开文本 项目封面
星标
54
复刻
49
最近推送(UTC)
2024年2月16日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

Build pub package codecov license

This Flutter package includes the widget ExpandableText which you can use to initially only show a defined number of lines of a probably long text. The widget appends a configurable text link which lets the user expand the full text, or collapse it again.

Example with maxLines=1

Getting started

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

dependencies:
  expandable_text: 2.3.0

Next, import the package into your dart code:

import 'package:expandable_text/expandable_text.dart';
Usage

Show an expandable text if longText exceeds one line:

Widget build(BuildContext context) {
    return ExpandableText(
        longText,
        expandText: 'show more',
        collapseText: 'show less',
        maxLines: 1,
        linkColor: Colors.blue,
    );
}
Advanced example

This example shows a message that was posted by a user. The username is always visible right before the text and tapping on it opens the user profile. The text is truncated after two lines and can be expanded by tapping on the link show more at the end or the text itself. After the text was expanded it cannot be collapsed again as no collapseText was provided. URLs, @mentions and #hashtags in the text are styled differently and can be tapped to open the browser or the user profile.

Widget build(BuildContext context) {
    return ExpandableText(
        message,
        expandText: 'show more',
        maxLines: 2,
        linkColor: Colors.blue,
        animation: true,
        collapseOnTextTap: true,
        prefixText: username,
        onPrefixTap: () => showProfile(username),
        prefixStyle: TextStyle(fontWeight: FontWeight.bold),
        onHashtagTap: (name) => showHashtag(name),
        hashtagStyle: TextStyle(
            color: Color(0xFF30B6F9),
        ),
        onMentionTap: (username) => showProfile(username),
        mentionStyle: TextStyle(
            fontWeight: FontWeight.w600,
        ),
        onUrlTap: (url) => launchUrl(url),
        urlStyle: TextStyle(
            decoration: TextDecoration.underline,
        ),
    );
}

Features

  • Link to expand the collapsed text (expandText)
  • Expand and collapse animation (animation, animationDuration, animationCurve)
  • Optional link to collapse the expanded text (collapseText)
  • Configure the style of the link (linkStyle / linkColor)
  • Control whether the ellipsis is part of the link (linkEllipsis)
  • Optional prefix text with style and tap callback (prefixText, prefixStyle, onPrefixTap)
  • Text with tappable and styled links (onUrlTap, urlStyle)
  • Text with tappable and styled @mentions (onMentionTap, mentionStyle)
  • Text with tappable and styled #hashtags (onHashtagTap, hashtagStyle)
  • Configure the number of visible lines of the collapsed text (maxLines)
  • Control the default expanded state (expanded, onLinkTap)
  • Callback for expanded changed event (onExpandedChanged)
  • Tap on the text to expand or collapse the text (expandOnTextTap, collapseOnTextTap)

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.

Copyright & License

Code copyright 2020–2022 Florian Weinaug. Code released under the MIT license.

Florian Weinaug GitHub avatar
GitHub 作者

Florian Weinaug ↗

Passionate about Flutter, React, .NET, C#, Xamarin, UWP, UX, Usability, Domain Driven Design, Clean Code ...

Hamburg, Germany官方网站 ↗
语言Dart

分类

此仓库发布的插件

使用的依赖

依赖清单 2 项

  • flutter{"sdk":"flutter"}
  • flutter_test开发依赖{"sdk":"flutter"}

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗