-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy patheditorjs_view.dart
More file actions
45 lines (40 loc) · 1.24 KB
/
editorjs_view.dart
File metadata and controls
45 lines (40 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import 'package:flutter/material.dart';
import '../../data/datasources/json_document_source.dart';
import '../../domain/usecases/parse_document.dart';
import '../config/editor_config.dart';
/// Read-only viewer for EditorJS JSON content.
///
/// Parses [jsonData] and renders each block using the registered renderers.
/// Unknown block types are silently skipped.
///
/// Example:
/// ```dart
/// EditorJSView(jsonData: myJsonString)
/// ```
class EditorJSView extends StatelessWidget {
final String jsonData;
final EditorConfig config;
EditorJSView({
super.key,
required this.jsonData,
EditorConfig? config,
}) : config = config ?? EditorConfig();
@override
Widget build(BuildContext context) {
final source = JsonDocumentSource(registry: config.typeRegistry);
final document = ParseDocument(source)(jsonData);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final block in document.blocks) ...[
config.rendererRegistry.buildRenderer(
block,
config.styleConfig,
) ??
const SizedBox.shrink(),
const SizedBox(height: 8),
],
],
);
}
}