chore: allow users to supply decoration instead of only color (#1150)

This commit is contained in:
Richard Shiue 2025-11-05 09:56:08 +08:00 • committed by GitHub
commit daacca47da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 32 additions and 43 deletions

View file

@ -3,27 +3,28 @@ import 'package:flutter/material.dart';
/// If you want to customize the logic of how to convert a color string to a
/// [Color], you can set this variable.
typedef BlockComponentBackgroundColorDecorator = Color? Function(
typedef BlockComponentBackgroundColorDecorator = Decoration? Function(
Node node,
String colorString,
);
BlockComponentBackgroundColorDecorator? blockComponentBackgroundColorDecorator;
BlockComponentBackgroundColorDecorator? blockComponentDecorator;
mixin BlockComponentBackgroundColorMixin {
Node get node;
Color get backgroundColor {
Decoration? get decoration {
final colorString =
node.attributes[blockComponentBackgroundColor] as String?;
if (colorString == null) {
return Colors.transparent;
return null;
}
return blockComponentBackgroundColorDecorator?.call(
return blockComponentDecorator?.call(
node,
colorString,
) ??
colorString.tryToColor() ??
Colors.transparent;
BoxDecoration(
color: colorString.tryToColor(),
);
}
}

View file

@ -162,12 +162,10 @@ class _BulletedListBlockComponentWidgetState
);
child = Container(
color: withBackgroundColor ? backgroundColor : null,
child: Padding(
key: blockComponentKey,
padding: padding,
child: child,
),
decoration: withBackgroundColor ? decoration : null,
key: blockComponentKey,
padding: padding,
child: child,
);
child = BlockSelectionContainer(

View file

@ -185,12 +185,10 @@ class _HeadingBlockComponentWidgetState
child: child,
);
child = Padding(
child = Container(
padding: padding,
child: Container(
color: backgroundColor,
child: child,
),
decoration: decoration,
child: child,
);
if (widget.showActions && widget.actionBuilder != null) {

View file

@ -177,12 +177,10 @@ class _NumberedListBlockComponentWidgetState
);
child = Container(
color: withBackgroundColor ? backgroundColor : null,
child: Padding(
key: blockComponentKey,
padding: padding,
child: child,
),
key: blockComponentKey,
decoration: withBackgroundColor ? decoration : null,
padding: padding,
child: child,
);
child = BlockSelectionContainer(

View file

@ -187,12 +187,10 @@ class _ParagraphBlockComponentWidgetState
);
child = Container(
color: withBackgroundColor ? backgroundColor : null,
child: Padding(
key: blockComponentKey,
padding: padding,
child: child,
),
key: blockComponentKey,
decoration: withBackgroundColor ? decoration : null,
padding: padding,
child: child,
);
child = BlockSelectionContainer(

View file

@ -156,12 +156,10 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
);
child = Container(
color: backgroundColor,
child: Padding(
key: blockComponentKey,
padding: padding,
child: child,
),
decoration: decoration,
key: blockComponentKey,
padding: padding,
child: child,
);
child = BlockSelectionContainer(

View file

@ -197,12 +197,10 @@ class _TodoListBlockComponentWidgetState
);
child = Container(
color: withBackgroundColor ? backgroundColor : null,
child: Padding(
key: blockComponentKey,
padding: padding,
child: child,
),
decoration: withBackgroundColor ? decoration : null,
key: blockComponentKey,
padding: padding,
child: child,
);
child = BlockSelectionContainer(

View file

@ -138,7 +138,7 @@ mixin NestedBlockComponentStatefulWidgetMixin<
Positioned.fill(
left: cachedLeft,
child: Container(
color: backgroundColor,
decoration: decoration,
),
),
NestedListWidget(