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

패키지 상세v2.2.2

contentful_rich_text

Contentful 리치 텍스트 JSON 객체를 파싱하고 렌더링 가능한 Flutter 위젯 트리를 반환하는 리치 텍스트 렌더러

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.2만
좋아요
29
Pub 점수
140

패키지 설치

flutter pub add contentful_rich_text

패키지 개요

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

Contentful 리치 텍스트 JSON을 네이티브 플러터 위젯 트리로 렌더링하는 플러터 패키지입니다. 이 패키지는 Contentful에서 구조화된 리치 텍스트 콘텐츠를 파싱하여 서식, 링크, 이미지, 중첩 블록을 지원하며, 플러터 앱에서 동적이고 풍부한 UI를 가능하게 합니다. 이 패키지는 Contentful의 헤드리스 CMS와 원활하게 통합되도록 설계되어 개발자가 수동으로 위젯을 구성하지 않고도 에디토리얼 콘텐츠를 표시할 수 있도록 합니다.

사용 사례

  • 모바일 및 웹 앱에서 CMS가 생성한 리치 텍스트 렌더링
  • 서식이 적용된 기사 또는 블로그 게시물 표시
  • 링크 및 이미지와 같은 상호작용 콘텐츠 삽입
  • 다국어 콘텐츠 전달 지원
  • 구조화된 데이터에서 동적 UI 만들기

주요 기능

  • Contentful 리치 텍스트 JSON 직접 분석
  • 인라인 및 블록 수준 형식 지정 지원
  • 링크, 이미지 및 목록의 내장 처리
  • 사용자 정의 렌더러를 통한 확장 가능한 위젯 매핑
  • 모든 플러터 대상에 대한 크로스플랫폼 호환성

적합한 대상

  • 헤드리스 CMS로 콘텐츠풀을 사용하는 플러터 개발자
  • 백엔드에서 풍부하고 편집 가능한 콘텐츠가 필요한 앱
  • CMS를 통해 UI를 하드코딩하지 않고 콘텐츠를 관리하는 팀

고려 사항

  • Contentful 콘텐츠 모델의 올바른 설정이 필요합니다
  • 복잡한 레이아웃의 경우 사용자 지정 렌더링 로직이 필요할 수 있습니다
  • 성능은 렌더링된 콘텐츠의 복잡성에 따라 달라집니다
  • Contentful의 리치 텍스트 형식 사양에 제한됨

원본 README

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

Contentful Rich Text Renderer for Flutter

Rich Text renderer that parses Contentful Rich Text field JSON output and produces a Flutter Widget tree that can be displayed in a Flutter app.

Installation

To use this plugin, add contentful_rich_text as a dependency in your pubspec.yaml file.

Usage

Note: The json examples are samples of what Contentful's API can return. The getContentfulJson method is just a placeholder for where your code would call a method to get your data from the Contentful API.

Simple document with paragraph, no inline marks (bold/italic/underline)
Sample JSON
{
  "nodeType": "document",
  "content": [
    {
      "nodeType": "paragraph",
      "content": [
        {
          "nodeType": "text",
          "value": "Hello world!",
          "marks": []
        }
      ]
    }
  ]
}
Sample Dart implementation
import 'package:contentful_rich_text/contentful_rich_text.dart';

// getting data from Contentful, must be implemented in your project
// document will be a dynamic variable JSON map matching the above JSON
var document = getContentfulJson(); 

class Demo extends StatelessWidget {

@override
  Widget build(BuildContext context) {
    return ContentfulRichText(document).documentToWidgetTree;
    // Example widget tree produced:
    // Paragraph(
    //   Text(text: 'Hello World'),
    // );
  }
}
Simple document with paragraph, with bold and italic inline marks
Sample JSON
{
  "nodeType": "document",
  "content": [
    {
      "nodeType": "paragraph",
      "content": [
        {
          "nodeType": "text",
          "value": "Hello",
          "marks": [{ "type": "bold" }],
        },
        {
          "nodeType": "text",
          "value": " world!",
          "marks": [{ "type": "italic" }]
        }
      ]
    }
  ]
}
Sample Dart implementation
import 'package:contentful_rich_text/contentful_rich_text.dart';

// getting data from Contentful, must be implemented in your project
// document will be a dynamic variable JSON map matching the above JSON
var document = getContentfulJson();

class Demo extends StatelessWidget {

@override
  Widget build(BuildContext context) {
    return ContentfulRichText(document).documentToWidgetTree;
    // Example widget tree produced:
    // Paragraph(
    //   Text(
    //     text: '',
    //     children: <Widgets>[
    //       TextSpan(text: 'Hello', style: { fontWeight: FontWeight.bold }),
    //       TextSpan(text: ' world!', style: { fontStyle: FontStyle.italic }), 
    //     ],
    //   ),
    // );
  }
}
Simple document with paragraph, with bold and italic inline marks, using a custom renderer and mark

You can also pass custom renderers for both marks and nodes as an optional parameter like so:

Sample JSON
{
  "nodeType": "document",
  "data": {},
  "content": [
    {
      "nodeType": "paragraph",
      "data":{},
      "content": [
        {
          "nodeType": "text",
          "value": "Hello",
          "marks": [{ "type": "bold" }],
          "data": {}
        },
        {
          "nodeType": "text",
          "value": " world!",
          "marks": [{ "type": "italic" }],
          "data": {}
        }
      ]
    }
  ]
}
Sample Dart implementation
import 'package:contentful_rich_text/contentful_rich_text.dart';

// getting data from Contentful, must be implemented in your project
// document will be a dynamic variable JSON map matching the above JSON
var document = getContentfulJson();

var options = {
  renderMark: RenderMark defaultMarkRenderers = RenderMark({
    [MARKS.BOLD.value]: () => CustomBoldTextStyle, // returns TextStyle
  }),
  renderNode: RenderNode defaultNodeRenderers = RenderNode({
    [BLOCKS.PARAGRAPH.value]: (node, next) => CustomParagraph(next: next(node.content))
  })
}

class Demo extends StatelessWidget {

@override
  Widget build(BuildContext context) {
    return ContentfulRichText(document, options).documentToWidgetTree;
    // Example widget tree produced:
    // CustomParagraph(
    //   textStyle: CustomBoldTextStyle(),
    //   ...
    // );
  }
}
RenderNodes

RenderNodes are the various content nodes that Contentful sends for the Rich Text Widget. Blocks are block level items, and inlines are inline items.

Note: Not all of the nodes sent from Contentful are currently implemented. See below for the implementation status.

The renderNode keys should be the value of one of the following BLOCKS and INLINES properties as defined in contentful_rich_text/types:

  • BLOCKS

    • DOCUMENT
    • PARAGRAPH
    • HEADING_1
    • HEADING_2
    • HEADING_3
    • HEADING_4
    • HEADING_5
    • HEADING_6
    • UL_LIST // partially implemented, nested lists are not implemented yet
    • OL_LIST // partially implemented, nested lists are not implemented yet
    • LIST_ITEM
    • QUOTE // not implemented yet
    • HR
    • EMBEDDED_ENTRY // not implemented yet
    • EMBEDDED_ASSET // not implemented yet
  • INLINES

    • HYPERLINK
    • EMBEDDED_ENTRY (this is different from the BLOCKS.EMBEDDED_ENTRY)
    • ENTRY_HYPERLINK // not implemented yet
    • ASSET_HYPERLINK // not implemented yet
RenderMarks

RenderMarks are the various text styles that can be applied to text inline.

Note: Not all of the marks sent from Contentful are currently implemented. See below for the implementation status.

The renderMark keys should be the value of one of the following MARKS properties as defined in contentful_rich_text/types:

  • BOLD
  • ITALIC
  • UNDERLINE
  • CODE // not implemented yet

카테고리

의존성

의존성 목록 3 개

소스 저장소

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

아직 데이터가 없습니다.