Flutter 在滚动时固定在一个位置的点击反弹时颤振
我正在使用我的小部件上的点击反弹功能。我参考了以下链接以获取信息:Flutter 在滚动时固定在一个位置的点击反弹时颤振,flutter,dart,flutter-animation,flutter-widget,Flutter,Dart,Flutter Animation,Flutter Widget,我正在使用我的小部件上的点击反弹功能。我参考了以下链接以获取信息: 我得到了这个名为的包,这对于解决方案来说已经足够好了,但是它有一个限制,即,它不适合滚动小部件。您不能通过点击使用此颤振反弹小部件的小部件来滚动页面 有人已经为上面的小部件创建了一个bug,但没有找到解决方案。以下是您可以找到问题的地方: 所以,我决定做我自己的小部件来完成这项工作。我制作了这个小部件,它工作正常,但有一个限制,即 当您按住小部件滚动页面时,小部件将保持在一个固定位置,这意味着它将保持在按下位置 这是我的
import 'package:flutter/material.dart';
class CLBounceWidget extends StatefulWidget {
final Function onPressed;
final Widget child;
CLBounceWidget({Key key, @required this.onPressed, @required this.child}): super(key:key);
@override
CLBounceWidgetState createState() => CLBounceWidgetState();
}
class CLBounceWidgetState extends State<CLBounceWidget> with SingleTickerProviderStateMixin{
double _scale;
final Duration duration = Duration(milliseconds: 200);
AnimationController _animationController;
//Getting onPressed Calback
VoidCallback get onPressed => widget.onPressed;
@override
void initState() {
_animationController = AnimationController(
vsync: this,
duration: duration,
lowerBound: 0.0,
upperBound: 0.1
)..addListener((){ setState((){}); });
super.initState();
}
@override
void dispose() {
// TODO: implement dispose
_animationController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
_scale = 1 - _animationController.value;
return GestureDetector(
onTapDown: _onTapDown,
onTapUp: _onTapUp,
child: Transform.scale(
scale: _scale,
child: widget.child
)
);
}
// Triggering the onPressed callback with a check
void _onTapTrigger(){
if(onPressed != null){
onPressed();
}
}
//Start the animation
_onTapDown(TapDownDetails details){
_animationController.forward();
}
// We revise the animation and notify the user of the event
_onTapUp(TapUpDetails details){
Future.delayed(Duration(milliseconds: 100), (){
_animationController.reverse();
});
//Finally calling the callback function
_onTapTrigger();
}
}
尝试:我尝试使用onLongPress
,onLongPressEnd
,onLongPressMoveUpdate
至少执行\u animationController.reverse(),但对我来说没有任何效果
当我拿着小部件滚动页面时,我希望小部件保持正常,就像普通小部件一样。因为经过长时间的研究和数小时的辛苦,我终于找到了我希望在项目中拥有的东西我已经创建了一个关于颤振的软件包,以帮助其他需要该软件包的开发人员。flutter\u bounce必须提供的功能。 您可以在上面的链接上搜索
flatter\u bounce
,也可以直接转到:
要利用它,您只需执行以下操作:
Bounce(
duration: Duration(milliseconds: 110),
onPressed: (){ YOUR_FUNCTION },
child: YOUR_WIDGET
)
有关更多详细信息,请随时阅读链接的
README
。它有所有必要的细节。快乐编码:)因为,经过长时间的研究和数小时的辛苦工作,我终于找到了我愿意在我的项目中拥有的东西我已经创建了一个关于颤振的软件包,以帮助其他需要该软件包的开发人员。flutter\u bounce必须提供的功能。
您可以在上面的链接上搜索flatter\u bounce
,也可以直接转到:
要利用它,您只需执行以下操作:
Bounce(
duration: Duration(milliseconds: 110),
onPressed: (){ YOUR_FUNCTION },
child: YOUR_WIDGET
)
有关更多详细信息,请随时阅读链接的README
。它有所有必要的细节。快乐编码:)