read_morex 1.2.0 copy "read_morex: ^1.2.0" to clipboard
read_morex: ^1.2.0 copied to clipboard

Display text with the option to expand, collapse it and also apply custom text filters to highlight or modify specific patterns within the text.

Read MoreX pub package #

The read_morex package is a Flutter widget that allows you to manage the display of long text with a "Read More" button that lets users expand to view the entire text or collapse it to a shorter version. It allows you to set a maximum number of lines and a maximum length for the text. When the content exceeds these limits, it provides a 'Read more' link, allowing users to see the full content, and a 'Show less' link to collapse it again. You can also apply custom text filters using regular expressions to highlight or modify specific patterns within the text. This widget offers flexibility and control over how text content is displayed and filtered within your Flutter app.

Example Screenshot

Installation #

You can import the read_morex package into your Flutter project by adding the following dependency to your pubspec.yaml file:

dependencies:
  read_morex: ^1.1.0

Don't forget to run flutter pub get after adding this dependency.

Usage #

Here's how to use it:

Import the read_morex package:

import 'package:read_morex/read_morex.dart';

Use the ReadMoreX widget in your layout:

Read More

ReadMoreX(
    'This is a very long text. You can tap the "Read More" button to see more text. Suspendisse interdum consectetur libero id faucibus nisl tincidunt eget nullam. Eu nisl nunc mi ipsum faucibus vitae aliquet nec.',
    textStyle: const TextStyle(fontSize: 18),
    readMoreColor: Colors.green,
    fontWeightLabel: FontWeight.normal,
),

Read More with Filter

ReadMoreX(
    'Link: https://github.com/tro1d\nAlternative link: https://flutter.dev\nEmail: readmorex@demo.com\nPhone: 0808080889',
    textStyle: const TextStyle(fontSize: 18),
    readMoreColor: Colors.green,
    filterContent: true,
    fontWeightLabel: FontWeight.normal,
    customFilter: <ReadMoreXPattern>[
        ReadMoreXPattern(
            pattern: r'github.com', // Sensitive https://
            valueChanged: (value) => value?.replaceFirst('https://github.com/', 'Github '),
            onTap: (value) {
                ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('This Link $value')),
                );
            },
        ),
        ReadMoreXPattern(
            pattern: r'https://', // Sensitive https:// , after github.com
            onTap: (value) {
                ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('This Link $value')),
                );
            },
        ),
        ReadMoreXPattern(
            pattern: r'\b[0-9]{9,}\b',
            colorChanged: Colors.red,
            onTap: (value) {
                ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('This Number $value')),
                );
            },
        ),
        ReadMoreXPattern(
            pattern: r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b',
            colorChanged: Colors.deepPurple,
            onTap: (value) {
                ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('This Email $value')),
                );
            },
        ),
    ],
),

Full example can be found at example/lib/main.dart.

10
likes
145
points
33
downloads

Publisher

unverified uploader

Weekly Downloads

Display text with the option to expand, collapse it and also apply custom text filters to highlight or modify specific patterns within the text.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on read_morex