rich_highlight_text_codespark 0.0.2

SDKflutter
Platformandroidioswindowslinuxmacosweb

Adds extension methods to highlight substrings in Text or String using Text.rich and custom styles. Simple inline highlighting with minimal code.

Banner

✨ rich_highlight_text_codespark

Pub Version
GitHub

Highlight specific substrings within your Flutter Text widgets effortlessly. Whether it's a single word or multiple phrases, rich_highlight_text_codespark provides a seamless way to emphasize parts of your text with customizable styles.

🎯 Fully null-safe and optimized for performance.

🚀 Features

  • ✅ Highlight single or multiple substrings
  • ✅ Support for case-sensitive and case-insensitive matching
  • ✅ Highlight modes: first occurrence, last occurrence, or all occurrences
  • ✅ Handles overlapping and adjacent matches gracefully
  • ✅ Customizable highlight styles
  • ✅ Seamless integration with existing Text widgets

📦 Installation

Add the following to your pubspec.yaml:

dependencies:
  rich_highlight_text: ^1.0.0

Then, run:

flutter pub get

🧪 Usage

🔍 Highlight a Single Substring

import 'package:flutter/material.dart';
import 'package:rich_highlight_text/rich_highlight_text.dart';

Text(
  'Welcome to Flutter!',
  style: TextStyle(fontSize: 18),
).highlight(
  'Flutter',
  highlightStyle: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold),
);
'Flutter is fun and powerful!'.toRichText(
  style: TextStyle(fontSize: 18),
  highlights: ['Flutter', 'powerful'],
  highlightStyle: TextStyle(color: Colors.orange, fontWeight: FontWeight.bold),
  onTap: (text) {
    print('Tapped: $text');
  },
);
Text(
  'Flutter is fun and powerful!',
  style: TextStyle(fontSize: 18),
).highlight(
  'Flutter',
  highlightStyle: TextStyle(
    color: Colors.blue,
    fontWeight: FontWeight.bold,
    decoration: TextDecoration.underline,
  ),
  onTap: (text) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text('You tapped on "$text"!')),
    );
  },
);

✨ Highlight Multiple Substrings

Text(
  'Flutter makes development faster and easier.',
  style: TextStyle(fontSize: 18),
).highlightMultiple(
  ['Flutter', 'faster', 'easier'],
  highlightStyle: TextStyle(color: Colors.green, fontWeight: FontWeight.bold),
);

🎯 Highlight Modes

  • HighlightMode.all: Highlights all occurrences (default)
  • HighlightMode.first: Highlights only the first occurrence
  • HighlightMode.last: Highlights only the last occurrence
Text(
  'Flutter is awesome. Flutter is fast.',
  style: TextStyle(fontSize: 18),
).highlight(
  'Flutter',
  highlightStyle: TextStyle(color: Colors.red),
  highlightMode: HighlightMode.first,
);

📸 Preview

Highlight Example 1

🛠️ API Reference

highlight

Text highlight(
  String highlightText, {
  TextStyle? highlightStyle,
  bool caseSensitive = true,
  HighlightMode highlightMode = HighlightMode.all,
  // Additional Text parameters...
});

highlightMultiple

Text highlightMultiple(
  List<String> highlightTexts, {
  TextStyle? highlightStyle,
  bool caseSensitive = true,
  HighlightMode highlightMode = HighlightMode.all,
  // Additional Text parameters...
});

📈 Roadmap

  • Highlight single substring
  • Highlight multiple substrings
  • Support for different highlight modes
  • Support for regular expressions
  • Animation support for highlights
  • Integration with SelectableText

🌍 Internationalization

✅ Supports Unicode and multilingual characters. 🌐 Fully compatible with languages like Arabic, Chinese, Hindi, and more.

📂 Example

Clone the repository and navigate to the example/ directory:

git clone https://github.com/Katayath-Sai-Kiran/rich_highlight_text.git
cd rich_highlight_text/example
flutter run

🙌 Contributions

Contributions are welcome! Please open issues and submit pull requests for any features, bugs, or enhancements.

👨‍💻 Maintainer

Developed with ❤️ by Katayath Sai Kiran