build method
Override this method to build widgets that depend on the state of the listenable (e.g., the current value of the animation).
Implementation
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constrains) {
final scanningGradientHeight =
constrains.maxHeight * scanningHeightOffset;
final animation = listenable as Animation<double>;
final value = isGoingUpDown ? 1.0 - animation.value : animation.value;
final scorePosition =
(value * constrains.maxHeight * 2) - (constrains.maxHeight);
final color = scanningColor ?? Colors.blue;
final isAnimationGoingDown = checkGoingUpDown(animation: animation);
var begin =
isAnimationGoingDown ? Alignment.topCenter : Alignment.bottomCenter;
var end =
isAnimationGoingDown ? Alignment.bottomCenter : Alignment.topCenter;
var colors = isAnimationGoingDown
? [
color.withOpacity(0.05),
color.withOpacity(0.1),
color.withOpacity(0.4),
color,
color,
]
: [
color.withOpacity(0.02),
color.withOpacity(0.1),
color.withOpacity(0.4),
color.withOpacity(0.4),
color,
];
return Stack(
children: [
Container(
height: scanningGradientHeight,
transform: Matrix4.translationValues(0, scorePosition, 0),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: begin,
end: end,
stops: const [
0.0,
0.2,
0.9,
0.95,
1,
],
colors: colors,
),
),
),
],
);
},
);
}