Coder Social home page Coder Social logo

marci002 / readmore Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonataslaw/readmore

0.0 0.0 0.0 2.79 MB

A Flutter plugin than allow expand and collapse text dynamically

License: MIT License

Objective-C 0.11% Kotlin 0.36% Dart 98.36% Swift 1.17%

readmore's Introduction

readmore

A Flutter plugin that allows for expanding and collapsing text with the added capability to style and interact with specific patterns in the text like hashtags, URLs, and mentions using the Annotation feature.

Usage:

Add the package to your pubspec.yaml:

readmore: ^3.0.0

Then, import it in your Dart code:

import 'package:readmore/readmore.dart';

Basic Example

ReadMoreText(
  'Flutter is Google’s mobile UI open source framework to build high-quality native (super fast) interfaces for iOS and Android apps with the unified codebase.',
  trimMode: TrimMode.Line,
  trimLines: 2,
  colorClickableText: Colors.pink,
  trimCollapsedText: 'Show more',
  trimExpandedText: 'Show less',
  moreStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
);

Rich Text Example

With the ReadMoreText.rich constructor, you can create text with rich formatting, including different colors, decorations, letter spacing, and interactive elements within a single widget.

ReadMoreText.rich(
  TextSpan(
    style: const TextStyle(color: Colors.black),
    children: [
      const TextSpan(text: 'Rich '),
      const TextSpan(
        text: 'Text',
        style: TextStyle(
          color: Colors.blue,
          decoration: TextDecoration.underline,
          letterSpacing: 5,
          recognizer: TapGestureRecognizer()..onTap = () {
            // Handle tap
          },
        ),
      ),
    ],
  ),
  trimMode: TrimMode.Line,
  trimLines: 2,
  colorClickableText: Colors.pink,
  trimCollapsedText: '...Read more',
  trimExpandedText: ' Less',
);

Using Annotations

The Annotation feature enhances the interactivity and functionality of the text content. You can define custom styles and interactions for patterns like hashtags, URLs, and mentions.

ReadMoreText(
  'This is a sample text with a #hashtag, a mention <@123>, and a URL: https://example.com.',
  trimMode: TrimMode.Line,
  trimLines: 2,
  colorClickableText: Colors.pink,
  annotations: [
    Annotation(
      regExp: RegExp(r'#([a-zA-Z0-9_]+)'),
      spanBuilder: ({required String text, required TextStyle textStyle}) => TextSpan(
        text: text,
        style: textStyle.copyWith(color: Colors.blue),
      ),
    ),
    Annotation(
      regExp: RegExp(r'<@(\d+)>'),
      spanBuilder: ({required String text, required TextStyle textStyle}) => TextSpan(
        text: 'User123',
        style: textStyle.copyWith(color: Colors.green),
        recognizer: TapGestureRecognizer()..onTap = () {
          // Handle tap, e.g., navigate to a user profile
        },
      ),
    ),
    // Additional annotations for URLs...
  ],
  moreStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
);

Note: This feature is not available with the ReadMoreText.rich constructor, as TextSpan gives you total control over styling and adding interactions to parts of the text.

readmore's People

Contributors

amereii avatar andreaselia avatar epynic avatar govindmaheshwari2 avatar jonataslaw avatar marci002 avatar olisaemekaejiofor avatar siqlain-hanif avatar sm2017 avatar takinok avatar unger1984 avatar webdastur avatar zeeshanhussain avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.