chore: allow users to supply decoration instead of only color (#1150)
This commit is contained in:
parent
de34eee281
commit
daacca47da
8 changed files with 32 additions and 43 deletions
|
|
@ -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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ mixin NestedBlockComponentStatefulWidgetMixin<
|
|||
Positioned.fill(
|
||||
left: cachedLeft,
|
||||
child: Container(
|
||||
color: backgroundColor,
|
||||
decoration: decoration,
|
||||
),
|
||||
),
|
||||
NestedListWidget(
|
||||
|
|
|
|||
Loading…
Reference in a new issue