WidgetDecoration class
Show widget as decoration on the chart
If using this as item that will show values make sure you apply margin from ChartState.defaultMargin this will make sure you are in chart area when you draw your decoration.
Example of drawing TargetLineDecoration with WidgetDecoration:
WidgetDecoration(
builder: (context, chartState, itemWidth, verticalMultiplier) {
return Container(
// This will make sure that child is in chart area.
margin: chartState.defaultMargin,
child: Stack(
children: [
// This will show a target line that can also be shown by using [TargetLineDecoration]
Positioned(
left: 0,
right: 0,
// Show target line at item height of 4
bottom: 4 * verticalMultiplier,
height: 2,
child: Container(color: Colors.red),
),
],
),
);
},
),
In case you just want to add image or something that is not relevant to current chart data you don't have to set any margins
- Inheritance
-
- Object
- DecorationPainter
- WidgetDecoration
Constructors
- WidgetDecoration({required WidgetDecorationBuilder widgetDecorationBuilder, EdgeInsets margin = EdgeInsets.zero})
- Constructor for selected item decoration
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- margin → EdgeInsets
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- widgetDecorationBuilder → WidgetDecorationBuilder
-
Builder for widget decoration
final
Methods
-
animateTo(
DecorationPainter endValue, double t) → DecorationPainter -
Animate to next decoration state, each decoration should implement this.
This is just regular lerp function, but instead of static function where you pass start and
end state, here we start with current state and animate to
endValue
.override -
applyPaintTransform(
ChartState state, Size size) → Offset -
inherited
-
draw(
Canvas canvas, Size size, ChartState state) → void -
Draw decoration.
Decoration can be foreground or background decoration that will be drawn on the chart
decorations can ignore padding and can use whole available canvas to draw.
override
-
getRenderer(
ChartState state) → Widget -
override
-
initDecoration(
ChartState state) → void -
Init decoration is first thing called on decorations, it will pass current ChartState
so decoration can easily calculate needed stuff for their layout.
inherited
-
isSameType(
DecorationPainter other) → bool -
Used for animating, we just need to find matching type, don't actually check for equality since we want to animate
from one state to other. Some decorations may consider overriding this in case multiples are used
inherited
-
layoutSize(
BoxConstraints constraints, ChartState state) → Size -
inherited
-
marginNeeded(
) → EdgeInsets -
Get extra margin (not definable by the user). This makes sure that any decoration
that leaves original drawing window is not drawing outside of that window (This is not
enforced right now but it's unwanted behaviour)
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paddingNeeded(
) → EdgeInsets -
Get extra padding (not definable by user, calculated by decoration if needed). This makes sure
that decoration will fit with the chart in wanted area.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited