FLUTTER ECOSYSTEM

elrizwiraswara/regexed_text

이 패키지는 주어진 정규 표현식 패턴 목록과 일치하는 텍스트를 강조 표시하기 위한 추가 기능을 제공하기 위해 Text 위젯을 확장합니다.

regexed_text 프로젝트 이미지
Stars
3
Forks
0
최근 푸시(UTC)
2025. 7. 22.
프로젝트 상태
활성
Elriz Wiraswara GitHub avatar
GITHUB User

Elriz Wiraswara ↗

making stuff & figuring things out

언어Dart

기술 주제

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 3 개
  • flutter{"sdk":"flutter"}
  • flutter_test개발 의존성{"sdk":"flutter"}
  • flutter_lints개발 의존성^3.0.0

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

RegexedText

This package extends the Text widget to provide additional functionality for highlighting text that matches a given list of RegExp patterns.

Key Features
  • Highlight parts of the text that match certain patterns. Each pattern can have its own unique style.
  • Handle taps on a part of the text that matches a pattern.
  • Extend the functionality of the Flutter Text widget.

Installation

Add the following to your pubspec.yaml file:

dependencies:
  regexed_text: ^0.0.7

Then run flutter pub get to install the package.

Usage

Basic Usage

screenshoot

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

const longTextExample = """
Hello @johnDoe, I found this interesting website that you might like: https://www.example.com. It has a lot of useful resources. Also, check out www.another-example.com for more related content. By the way, I came across @janeDoe profile, and it seems she has similar interests. You can connect with her. Lastly, don't forget to visit example.com for the latest updates.

You can reach out to me at john.doe@example.com. I'm always open to discussing new ideas. Also, did you check out the latest trend on social media? The hashtag #example is trending right now!

By the way, I found this phone number +1-123-456-7890 in my old contacts. I think it belongs to our mutual friend. And, don't forget our meeting on 12/31/2022. Looking forward to it!
""";

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('RegexedText example'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(18),
          child: RegexedText(
            longTextExample,
            patterns: [
              usernamePattern,
              urlPattern,
              emailPattern,
              hashtagPattern,
              phoneNumberPattern,
              datePattern,
            ],
            normalStyle: const TextStyle(color: Colors.black),
            regexedStyle: (pattern) {
              if (pattern == usernamePattern) {
                return const TextStyle(
                  color: Colors.red,
                  fontWeight: FontWeight.w600,
                );
              }

              if (pattern == hashtagPattern) {
                return const TextStyle(
                  color: Colors.blue,
                  fontWeight: FontWeight.w600,
                );
              }

              if (pattern == datePattern) {
                return const TextStyle(
                  color: Colors.black,
                  fontWeight: FontWeight.w600,
                );
              }

              return const TextStyle(
                color: Colors.blue,
                decoration: TextDecoration.underline,
              );
            },
            onTap: (text, pattern) {
              print(text);
              print(pattern);

              if (pattern == urlPattern) {
                // Launch [text] with url_launcher or something
              }
            },
          ),
        ),
      ),
    );
  }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.