패키지, 저장소 및 앱 카테고리 검색

flutter_parsed_text 표지
패키지 상세v2.2.1

flutter_parsed_text

텍스트를 파싱하여 여러 개의 Flutter Text 위젯으로 만드는 Flutter 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
25.8만
좋아요
270
Pub 점수
150

패키지 설치

flutter pub add flutter_parsed_text

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

특정 패턴(예: URL, 이메일, 해시태그 등)을 자동으로 상호작용 가능한 텍스트 위젯으로 변환할 수 있는 플러터 패키지입니다. 클릭 가능한 요소를 포함한 포맷된 텍스트 렌더링 과정을 간소화하여 동적 콘텐츠를 표시하는 앱의 사용자 경험을 향상시킵니다. 이 패키지는 여러 플랫폼을 지원하며 기존 플러터 프로젝트에 원활하게 통합됩니다. 채팅 인터페이스, 소셜 미디어 피드 또는 어떤 UI에서도 풍부한 텍스트 파싱이 필요한 경우에 이상적입니다.

사용 사례

  • 채팅 메시지 내 URL 파싱
  • 해시태그 및 언급 강조
  • 클릭 가능한 이메일 링크 만들기
  • 소셜 피드에서 리치 텍스트 렌더링
  • 서식이 적용된 사용자 생성 콘텐츠 표시

주요 기능

  • URL, 이메일 및 해시태그의 자동 감지
  • 구문 분석된 텍스트를 위한 사용자 정의 스타일
  • 여러 플랫폼 대상을 지원합니다
  • 기존 Text 위젯과의 간편한 통합
  • 확장 가능한 패턴 매칭 시스템

적합한 대상

  • 채팅 및 메시징 앱
  • 소셜 미디어 애플리케이션
  • 동적 텍스트를 갖춘 콘텐츠가 풍부한 UI
  • 상호작용 텍스트 요소가 필요한 앱
  • 경량 텍스트 파싱을 원하는 개발자

고려 사항

  • 고급 패턴을 위해 사용자 정의 정규식이 필요할 수 있습니다
  • 매우 긴 텍스트로 인한 성능 영향
  • 복잡한 형식 지정에 대한 내장 지원이 제한적입니다
  • 중첩된 텍스트 구조를 주의 깊게 다뤄야 합니다
  • 실시간 스트리밍 텍스트에 최적화되지 않음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

🔗 Flutter Parsed text

A Flutter package to parse text and extract parts using predefined types like url, phone and email and also supports Regex.

Usage 💻

To use this package, add flutter_parsed_text as a dependency in your pubspec.yaml file.

import 'package:flutter_parsed_text/flutter_parsed_text.dart';

Working ⚙️

ParsedText can receive this paramters & all the RichText parameters:

text: Text that will be parsed and rendered.

style: It takes a TextStyle object as it's property to style all the non links text objects.

parse: Array of MatchText object - used for defining structure for pattern matching .

MatchText(
  type: ParsedType.EMAIL, // predefined type can be any of this ParsedTypes
  style: TextStyle(
    color: Colors.red,
    fontSize: 24,
  ), // custom style to be applied to this matched text
  onTap: (url) {
    // do something here with passed url
  }, // callback funtion when the text is tapped on
),

You can also define a custom pattern like this:

MatchText(
  pattern: r"\B#+([\w]+)\b", // a custom pattern to match
  style: TextStyle(
    color: Colors.pink,
    fontSize: 24,
  ), // custom style to be applied to this matched text
  onTap: (url) async {
  // do something here with passed url
  }, // callback funtion when the text is tapped on
)

You can also set RegexOption for the custom regex pattern like so:

MatchText(
  pattern: r"\B#+([\w]+)\b", // a custom pattern to match
  regexOptions: RegexOptions(
    multiLine : false,
    caseSensitive : false,
    unicode : false,
    dotAll : false
  ),
  style: TextStyle(
    color: Colors.pink,
    fontSize: 24,
  ), // custom style to be applied to this matched text
  onTap: (url) async {
  // do something here with passed url
  }, // callback funtion when the text is tapped on
)

A boolean that show a diffrent text and passes a diffrent text to the callback

eg: Your str is "Mention [@michel:5455345]" where 5455345 is ID of this user which will be passed as parameter to the callback funtion and @michel the value to display on interface. Your pattern for ID & username extraction : /\[(@[^:]+):([^\]]+)\]/i

Displayed text will be : Mention ^^@michel^^

MatchText(
  pattern: r"\[(@[^:]+):([^\]]+)\]",
  style: TextStyle(
    color: Colors.green,
    fontSize: 24,
  ),
  // you must return a map with two keys
  // [display] - the text you want to show to the user
  // [value] - the value underneath it
  renderText: ({String str, String pattern}) {
    Map<String, String> map = Map<String, String>();
    RegExp customRegExp = RegExp(pattern);
    Match match = customRegExp.firstMatch(str);
    map['display'] = match.group(1);
    map['value'] = match.group(2);
    return map;
  },
  onTap: (url) {
    // do something here with passed url
  },
),

Example ✍🏻

Find the complete example wiring in the Flutter_Parsed_Text example application.

A small example of the ParsedText widget.

ParsedText(
  text:
    "[@michael:51515151] Hello this is an example of the ParsedText, links like http://www.google.com or http://www.facebook.com are clickable and phone number 444-555-6666 can call too. But you can also do more with this package, for example Bob will change style and David too. foo@gmail.com And the magic number is 42! #react #react-native",
  parse: <MatchText>[
    MatchText(
      type: ParsedType.EMAIL,
      style: TextStyle(
        color: Colors.red,
        fontSize: 24,
      ),
      onTap: (url) {
        launch("mailto:" + url);
      },
    ),
  ],
)

Found this project useful? ❤️

If you found this project useful, then please consider giving it a ⭐️ on Github and sharing it with your friends via social media.

API details 👨🏻‍💻

See the flutter_parsed_text.dart for more API details

License ⚖️

Issues and feedback 💭

If you have any suggestion for including a feature or if something doesn't work, feel free to open a Github issue for us to have a discussion on it.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트