apptomate_custom_text 0.0.2
apptomate_custom_text: ^0.0.2 copied to clipboard
A versatile text display widget with advanced features like read-more functionality, text selection, and customizable styling.
CustomText #
A versatile text display widget with advanced features like read-more functionality, text selection, and customizable styling.
Features #
- Multiple Display Modes:
- Standard text with ellipsis
- Read-more/read-less functionality
- Selectable text content
- Customizable Styling:
- Independent styles for main text and read-more controls
- Customizable expand/collapse labels
- Clickable text support
- Layout Control:
- Configurable margins
- Text alignment options
- Max lines control
- Accessibility:
- Disables text scaling
- Supports text selection
- Customizable touch targets
Installation #
Add the dependency to your pubspec.yaml:
dependencies:
apptomate_custom_text: ^0.0.2
Basic Usage #
// Standard text
CustomText(
txtName: "Hello World",
style: TextStyle(fontSize: 16),
)
// Read-more text
CustomText(
txtName: longText,
isReadMore: true,
maxLines: 3,
style: TextStyle(color: Colors.black),
)
// Selectable text
CustomText(
txtName: "Copy this text",
isSelectableText: true,
style: TextStyle(fontSize: 14),
)
Complete Example #
Column(
children: [
// Standard text with margin
CustomText(
txtName: "This is a simple text widget",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
margin: EdgeInsets.only(bottom: 16),
),
// Read-more text with custom styling
CustomText(
txtName: veryLongText,
isReadMore: true,
maxLines: 2,
style: TextStyle(color: Colors.grey[800], fontSize: 14),
moreStyle: TextStyle(color: Colors.blue),
lessStyle: TextStyle(color: Colors.green),
trimCollapsedText: "Show more...",
trimExpandedText: "Show less...",
),
// Clickable selectable text
CustomText(
txtName: "Tap to copy this text",
isSelectableText: true,
onTap: () => Clipboard.setData(ClipboardData(text: "Tap to copy this text")),
style: TextStyle(color: Colors.blue, decoration: TextDecoration.underline),
),
],
)
Parameter Reference #
Core Properties #
| Parameter | Type | Required | Description |
|---|---|---|---|
txtName |
String |
Yes | The text content to display |
style |
TextStyle |
Yes | Style for the main text |
Display Modes #
| Parameter | Type | Default | Description |
|---|---|---|---|
isReadMore |
bool |
false |
Enables read-more functionality |
isSelectableText |
bool? |
false |
Makes text selectable |
maxLines |
int? |
null |
Maximum lines before truncation |
Read-More Customization #
| Parameter | Type | Default | Description |
|---|---|---|---|
trimCollapsedText |
String |
"View more" | Text shown when collapsed |
trimExpandedText |
String |
"View less" | Text shown when expanded |
moreStyle |
TextStyle? |
Red bold | Style for "more" text |
lessStyle |
TextStyle? |
Purple bold | Style for "less" text |
clickableTextColor |
Color? |
Colors.black |
Color for clickable portions |
Layout & Interaction #
| Parameter | Type | Default | Description |
|---|---|---|---|
margin |
EdgeInsets? |
EdgeInsets.zero |
Outer margins |
align |
TextAlign? |
null |
Text alignment |
onTap |
Function()? |
null |
Tap callback handler |
Advanced Usage #
Custom Read-More Implementation #
CustomText(
txtName: longArticleText,
isReadMore: true,
maxLines: 3,
trimCollapsedText: "Continue reading...",
trimExpandedText: "Collapse article",
moreStyle: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w600,
),
lessStyle: TextStyle(
color: Colors.grey[600],
fontStyle: FontStyle.italic,
),
)
Themed Text Widgets #
Create a consistent text style across your app:
class AppTextStyles {
static const body = TextStyle(
fontSize: 14,
color: Colors.black87,
);
static const title = TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
);
}
// Usage
CustomText(
txtName: "App Title",
style: AppTextStyles.title,
)
Best Practices #
-
Performance:
- Avoid unnecessary text widget rebuilds
- For very long texts, consider
isReadMoreto improve performance - Use
constconstructors where possible
-
Accessibility:
- Ensure sufficient color contrast
- Maintain readable font sizes
- Provide adequate touch targets for interactive text
-
Internationalization:
- Make sure trim texts are localized
- Consider RTL (right-to-left) text alignment needs
Migration Guide #
When updating from previous versions:
- The widget now uses the
readmorepackage for expand/collapse functionality - Text scaling is now disabled by default
- Added support for text selection
- Improved parameter naming consistency