Introducing ReadMore: Expandable Text with Enhanced Annotation Capabilities for Flutter Apps
Published on by Flutter News Hub
Embrace Dynamic Text Content with ReadMore
The ReadMore plugin for Flutter empowers developers with the ability to create expandable and collapsible text sections within their mobile applications. This plugin offers seamless control over text display, allowing you to trim excess content and provide users with the option to expand and read more.
Get Started
To integrate ReadMore into your Flutter project, follow these simple steps:
- Add the package to your pubspec.yaml file:
readmore: ^3.0.0
- Import the plugin into your Dart code:
import 'package:readmore/readmore.dart';
Basic Usage: A Simple Example
Implement ReadMoreText to display expandable text with custom trim settings and interactive buttons:
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), );
Enhance Text Interaction with Annotations
ReadMore introduces the powerful Annotation feature, enabling you to define custom styles and interactions for specific patterns within your text. Leverage it to mark and style hashtags, URLs, and mentions:
ReadMoreText( 'This is a sample text with a #hashtag, a mention , and a URL: https://example.com.', trimMode: TrimMode.Line, trimLines: 2, colorClickableText: Colors.pink, annotations: [ Annotation( regExp: RegExp(r'#([a-zA-Z0-9_]+)'), spanBuilder: () => TextSpan( text: text, style: textStyle?.copyWith(color: Colors.blue), ), ), Annotation( regExp: RegExp(r'<@(\d+)>'), spanBuilder: () => 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), );
Elevate Your App Enhancements with ReadMore
By incorporating ReadMore into your Flutter development, you unlock a wealth of benefits:
- Dynamic Text Display: Control text length and provide expand/collapse functionality for enhanced readability.
- Customizable Interactions: Stylize and interact with specific patterns like hashtags, mentions, and URLs.
- Improved User Experience: Offer a seamless text experience, allowing users to focus on relevant information while minimizing visual clutter.
Conclusion
ReadMore serves as a valuable tool for Flutter developers seeking to deliver interactive and engaging text-based content. Its rich feature set and user-friendly interface make it a must-have for any app requiring dynamic and customizable text display.