This commit is contained in:
2026-07-12 04:33:48 +08:00
parent f8a90ad305
commit e7ce0f7bae
151 changed files with 2765 additions and 2947 deletions

View File

@@ -6,30 +6,30 @@ class ParabolicAnimationWidget extends AnimatedWidget {
final GlobalKey stackKey;
final GlobalKey startKey;
final GlobalKey endKey;
final double size;
final Color color;
final Offset startAdjustOffset;
final Offset endAdjustOffset;
final double? size;
final Color? color;
final Offset? startAdjustOffset;
final Offset? endAdjustOffset;
ParabolicAnimationWidget({
@required Animation<double> animation,
@required this.stackKey,
@required this.startKey,
@required this.endKey,
required Animation<double> animation,
required this.stackKey,
required this.startKey,
required this.endKey,
this.size = 20.0,
this.color = Colors.red,
this.startAdjustOffset = Offset.zero,
this.endAdjustOffset = Offset.zero,
}) : super(listenable: animation);
Offset _startOffset;
Offset _endOffset;
Offset _startOffset = Offset.zero;
Offset _endOffset = Offset.zero;
@override
Widget build(BuildContext context) {
_calPoints();
final Animation<double> animation = listenable;
final Animation<double> animation = listenable as Animation<double>;
final double time = animation.value;
// 设time=1 已知两点坐标 和 初速度 可求出 加速度 a
@@ -58,7 +58,7 @@ class ParabolicAnimationWidget extends AnimatedWidget {
width: size,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.all(Radius.circular(size / 2.0))),
borderRadius: BorderRadius.all(Radius.circular(size! / 2.0))),
),
),
);
@@ -66,26 +66,26 @@ class ParabolicAnimationWidget extends AnimatedWidget {
void _calPoints() {
if (_startOffset == null) {
RenderBox stackBox = stackKey.currentContext.findRenderObject();
RenderBox stackBox = stackKey.currentContext?.findRenderObject() as RenderBox;
Offset stackBoxOffset = stackBox.globalToLocal(Offset.zero);
EdgeInsets startMargin = _margin(startKey);
RenderBox startBox = startKey.currentContext.findRenderObject();
RenderBox startBox = startKey.currentContext?.findRenderObject() as RenderBox;
_startOffset = startBox.localToGlobal(Offset(
startMargin.left + startAdjustOffset.dx,
stackBoxOffset.dy + startMargin.top + startAdjustOffset.dy));
startMargin.left + startAdjustOffset!.dx,
stackBoxOffset.dy + startMargin.top + startAdjustOffset!.dy));
EdgeInsets endMargin = _margin(endKey);
RenderBox endBox = endKey.currentContext.findRenderObject();
RenderBox endBox = endKey.currentContext?.findRenderObject() as RenderBox;
_endOffset = endBox.localToGlobal(Offset(
endMargin.left + endAdjustOffset.dx,
stackBoxOffset.dy + endMargin.top + endAdjustOffset.dy));
endMargin.left + endAdjustOffset!.dx,
stackBoxOffset.dy + endMargin.top + endAdjustOffset!.dy));
}
}
EdgeInsets _margin(GlobalKey key) {
final Widget widget = key.currentContext.widget;
EdgeInsets margin = (widget is Container) ? widget.margin : EdgeInsets.zero;
final Widget widget = key.currentContext!.widget;
EdgeInsets margin = (widget is Container) ? widget.margin as EdgeInsets : EdgeInsets.zero;
return margin ?? EdgeInsets.zero;
}
}