text_highlight_codespark 1.0.1

SDKflutter
Platformandroidioswindowslinuxmacosweb

A Flutter package for highlighting text within a string, supporting single, multiple, and regex-based queries.

Banner

HighlightText

HighlightText is a Flutter widget that highlights specific parts of a given text. It supports case-sensitive searches, multiple queries, and regular expressions for advanced matching scenarios.

Screenshot

Single Query Highlighting Multiple Queries Highlighting Regex Highlighting

Features

  • Single Query Highlighting: Highlight a single query within the source text.
  • Multiple Queries Highlighting: Highlight multiple queries within the source text.
  • Regex Highlighting: Highlight matches based on a regular expression.
  • Case Sensitivity: Option to enable or disable case-sensitive searches.

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  text_highlight_codespark: ^1.0.1

Then, run flutter pub get to install the package.

Usage

Single Query Highlighting

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

class ExampleSingleQuery extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: HighlightText(
          query: 'highlight',
          source: 'This is a highlight text example.',
          highlightColor: Colors.yellow,
          textStyle: TextStyle(fontSize: 20),
          matchedTextStyle: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
          caseSensitive: false,
        ),
      ),
    );
  }
}

Multiple Queries Highlighting

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

class ExampleMultipleQueries extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: HighlightText.multiple(
          queires: ['highlight', 'text'],
          source: 'This is a highlight text example.',
          highlightColor: Colors.green,
          textStyle: TextStyle(fontSize: 20),
          matchedTextStyle: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
          caseSensitive: false,
        ),
      ),
    );
  }
}

Regex Highlighting

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

class ExampleRegex extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: HighlightText.regex(
          regex: r'\b\w{7}\b', // Highlights all 7-letter words
          source: 'This is an example with regex highlighting.',
          highlightColor: Colors.blue,
          textStyle: TextStyle(fontSize: 20),
          matchedTextStyle: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
          caseSensitive: false,
        ),
      ),
    );
  }
}

Constructor Parameters

HighlightText

ParameterTypeDefaultDescription
queryStringRequiredThe query string to highlight.
sourceStringRequiredThe source text in which to search.
highlightColorColorColors.redThe color used to highlight matches.
textStyleTextStylenullThe default style for non-matching text.
matchedTextStyleTextStylenullThe style for matching text.
caseSensitivebool?falseWhether the search is case-sensitive.

HighlightText.multiple

ParameterTypeDefaultDescription
queriesList<String>RequiredThe list of query strings to highlight.
sourceStringRequiredThe source text in which to search.
highlightColorColorColors.redThe color used to highlight matches.
textStyleTextStylenullThe default style for non-matching text.
matchedTextStyleTextStylenullThe style for matching text.
caseSensitivebool?falseWhether the search is case-sensitive.

HighlightText.regex

ParameterTypeDefaultDescription
regexStringRequiredThe regular expression to use.
sourceStringRequiredThe source text in which to search.
highlightColorColorColors.redThe color used to highlight matches.
textStyleTextStylenullThe default style for non-matching text.
matchedTextStyleTextStylenullThe style for matching text.
caseSensitivebool?falseWhether the search is case-sensitive.

License

MIT License