パッケージ、リポジトリ、アプリカテゴリを検索

parsed_readmore のカバー
パッケージ詳細v1.0.0

parsed_readmore

展開可能で、テキスト内のURLを自動的にクリック可能なリンクに変換できるFlutterのテキストウィジェットです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
327
いいね数
42
Pub ポイント
160

パッケージをインストール

flutter pub add parsed_readmore

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ParsedReadMore は、自動的な URL 検出とパースを備えた Flutter ウィジェットで、テキスト内のリンクをクリック可能なハイパーリンクに変換します。拡張可能なテキストをサポートしており、ユーザーが「続きを読む」トグルを使って追加のコンテンツを表示できます。埋め込まれた URL とやり取りする必要があるアプリでの豊富なテキスト表示に最適です。このウィジェットは、Android、iOS、Web、macOS、Windows、Linux を含むすべての主要プラットフォームで動作します。

用途

  • クリック可能なURLを含むリッチテキストの表示
  • 拡張可能なコンテンツセクションの作成
  • インタラクティブテキストによるユーザー参加の向上
  • アプリコンテンツにソーシャルメディアまたはウェブリンクを表示する
  • ブログスタイルのテキストスニペットの実装

主な機能

  • 自動的なURL検出とリンク
  • 展開可能/折りたたみ可能なテキスト
  • クロスプラットフォーム互換性
  • 複数のテキストスタイルをサポート
  • pub を通じたシンプルな統合
  • カスタマイズ可能な「続きを読む」ボタン

適している対象

  • コンテンツが豊富なアプリ
  • ソーシャルメディアインターフェース
  • ブログとニュースリーダー
  • 教育アプリ
  • ユーザーが生成したコンテンツが表示されます

注意事項

  • 複雑なテキストに対してスタイルの調整が必要になる場合があります
  • 非常に長いテキストによるパフォーマンスへの影響
  • URLの解析に限定(他のマークアップはなし)
  • 入力における正しいURL形式に依存する
  • リンク以外の高度に形式化されたリッチテキストには適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Parsed Readmore

Latest version has BREAKING CHANGES !

A Flutter package which allows the user to enter text which can be collapsed and expanded based on user defined trimming conditions. Nevertheless, it will automatically parse the user regex patterns (urls by default) present in the text into clickable hyperlinks with a user defined click action (browser launch by default). It also allows the user to enter a highlight text on which some custom text style can be applied with the support of multiple text phrases (priority based).

Latest release: https://pub.dev/packages/parsed_readmore

Features

  • Expandable and Collapsable text.
  • Trimming can either be done on basis of length or number of lines.
  • Option to include a customised delimiter.
  • Automatically parses the urls present in the text into hyperlinks which launches the browser on click event (default behaviour).
  • All the text components including the parsed urls, delimiter, clickable texts, etc can be given seperate custom styles.
  • Addition of user defined action on clicking the hyperlinks.
  • Using custom text styles for target text (also refered as text highlighting).
  • Multiword highlighting. We are using priority (int) to resolve the clash of phrases. For example, if we have 2 phrases 'the' and 't' and the priority of 't' is higher then the style of letter 't' will be used while 'he' of 'the' will have the style of the style of 'the'. (latest)
  • Option to use custom regex for Url/pattern regonition. (latest)

Installation

Run this command in your terminal

flutter pub add parsed_readmore

Or add it manually in your project's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  parsed_readmore: latest_version

Import parsed_readmore.dart in the file where you wish to use

import 'package:parsed_readmore/parsed_readmore.dart';

Usage Example

For detailed implementation refer to the "Example" tab

We will be using a common input string to demonstrate the different uses cases of this package.

 const inputString = "When using custom values we have specified 'the' to be our target text for highlighting  with purple italic font.\n We know that the website https://google.com is a very useful website. (rti..notNow should not be parsed) But Instagram.com is more fun to use. We should not forget the contribution of wikipedia.com played in the growth of web. If you like this package do consider liking it so that it could be useful to more developers like you. Thank you for your time";
Without using package (Plain Text)

Here we are using the simple Text() widget available in Flutter by default.

  Text(inputString);
Plain Text

We can clearly see that no url is parsed here into clickable texts and there is no option to expand and collapse the texts.

Using package with default values
ParsedReadMore(TextHighlightParser(data: inputData))
Default Package

The code above will implement all features of the widget with the default values which are :

  • trimMode = TrimMode.length
  • delimiter = ' ...'
  • trimLength = 240
  • readLessText = 'show less',
  • readMoreText = 'read more',
  • urlRegex = r'([\w+]+://)?([\w\d-]+.)*[\w-]+[.][a-z0-9_]+([/?=&#.]?[\w-]){1,}/?' (regex for url detection)
  • if onTapLink == null --> url will be launched in extrenal browser.

Here the urls are parsed into clickable links which open external browser on tapping. The text is also collapsable and expandable

Using package with custom values
ParsedReadMore(
  TextHighlightParser(
    urlRegex: r'https:\/\/[^\s]+',
    data: inputData,
    initialState: ReadMoreState.collapsed,
    urlTextStyle: textStyle.copyWith(
      color: Colors.green,
      decoration: TextDecoration.underline,
    ),
    trimMode: TrimMode.line,
    maxLines: 2,
    onTapLink: (url) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text(
            """'$url' is displayed because we have used custom onTap function for hyperlinks""",
          ),
        ),
      );
    },
    targetTextHighlights: TargetTextHighlights(targetHighlights: [
      TargetTextHighlight(
        priority: 1,
        targetText: 'The',
        style: TextStyle(
          fontSize: 20.0,
          fontStyle: FontStyle.italic,
          color: Colors.blue[900],
        ),
      ),
      TargetTextHighlight(
          priority: 2,
          targetText: 'he',
          highlightInUrl: true,
          style: const TextStyle(
            fontSize: 20.0,
            color: Colors.purple,
          ),
          onTap: (range) {
            ScaffoldMessenger.of(context).showSnackBar(
              SnackBar(
                content: Text(
                    "'${range.textInside(inputData)}' is between the character no ${range.start} and ${range.end}"),
              ),
            );
          }),
    ]),
  ),
  readMoreDelimiter: '+++',
  readLessDelimiter: ' ---',
  readMoreDelimiterStyle: textStyle.copyWith(color: Colors.black),
  readLessDelimiterStyle: textStyle.copyWith(color: Colors.black),
  style: textStyle.copyWith(color: Colors.grey),
  readMoreText: ' expand',
  readLessText: ' compress',
  readMoreTextStyle: textStyle.copyWith(color: Colors.blue),
  readLessTextStyle: textStyle.copyWith(color: Colors.pink),
)
Custom Package
Highlight points here:
  • Custom regex for recognizing only the 'https' urls.
  • Custom text style for the urls
  • Custom click action for the Urls (Snackbar instead of browser launch)
  • Multiple text highlights using 'targetTextHighlights' attribute
  • Custom text style and click actions (optional) for the highlights
  • An important point to note here is that, In case of clash of the mutliples highlights, we are using the 'priority' attribute of each TargetTextHighlight. The target text having numerical value of the priority greater will be override the style of the lower priority highlight.
  • Custom delimiters
  • Custom text style for the non-url and the non-highlight texts
  • Custom readMore and readLess texts

Issues

Please file any issues, bugs or feature request as an issue on the GitHub page. If you have some idea for feature upgrade, feel free to contact me through email [aashish.260401@gmail.com](mailto:aashish.260401@gmail.com).

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト