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
|
/// 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(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ mixin NestedBlockComponentStatefulWidgetMixin<
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
left: cachedLeft,
|
left: cachedLeft,
|
||||||
child: Container(
|
child: Container(
|
||||||
color: backgroundColor,
|
decoration: decoration,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
NestedListWidget(
|
NestedListWidget(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue