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 /// If you want to customize the logic of how to convert a color string to a
/// [Color], you can set this variable. /// [Color], you can set this variable.
typedef BlockComponentBackgroundColorDecorator = Color? Function( typedef BlockComponentBackgroundColorDecorator = Decoration? Function(
Node node, Node node,
String colorString, String colorString,
); );
BlockComponentBackgroundColorDecorator? blockComponentBackgroundColorDecorator; BlockComponentBackgroundColorDecorator? blockComponentDecorator;
mixin BlockComponentBackgroundColorMixin { mixin BlockComponentBackgroundColorMixin {
Node get node; Node get node;
Color get backgroundColor { Decoration? get decoration {
final colorString = final colorString =
node.attributes[blockComponentBackgroundColor] as String?; node.attributes[blockComponentBackgroundColor] as String?;
if (colorString == null) { if (colorString == null) {
return Colors.transparent; return null;
} }
return blockComponentBackgroundColorDecorator?.call( return blockComponentDecorator?.call(
node, node,
colorString, colorString,
) ?? ) ??
colorString.tryToColor() ?? BoxDecoration(
Colors.transparent; color: colorString.tryToColor(),
);
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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