Guides
Creating Custom Deltas
Create custom delta classes for transformations not provided out of the box.
If you are not yet familiar with deltas, see the customizing widget styles guide first.
When the built-in delta factory constructors do not cover your use case, implement the delta class directly and override
call.
Suppose you want to mirror a widget's EdgeInsets padding. To do so, implement EdgeInsetsDelta with a call method
that swaps the edges:
1class MirrorDelta implements EdgeInsetsDelta {2 const MirrorDelta();34 @override5 EdgeInsets call(EdgeInsets? insets) {6 final resolved = insets ?? .zero;7 return .only(8 left: resolved.right,9 top: resolved.top,10 right: resolved.left,11 bottom: resolved.bottom,12 );13 }14}15Pass it anywhere an EdgeInsetsDelta is accepted:
1FTooltip(2 style: const .delta(padding: MirrorDelta()),3 tipBuilder: (_, _) => const Text('Tooltip'),4 child: const Placeholder(),5);6The same pattern works for any delta class. Implement it and override call.