【发布时间】:2020-09-22 12:11:56
【问题描述】:
Scaffold 的 floatingActionButton 属性接受任何小部件,因此我在那里使用一排几个自定义容器来利用浮动效果。我已将 floatingActionButtonLocation 属性设置为“centerFloat”。问题是,每当我使用这样的小部件推送新页面时,它都会使用我想要禁用的奇怪动画。我发现了这个:Disable Scaffold FAB animation,所以我扩展了 FloatingActionButtonAnimator 并尝试了上述示例中显示的内容,但不幸的是,它没有帮助。我轻松地处理了偏移量。但旋转和缩放动画仍然存在。即使调整 Tween 对象的开始和结束值也无济于事。
这是脚手架中的设置:
floatingActionButton: ActionControls(),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButtonAnimator: NoScalingAnimation(),
这些是 ActionControl,基本上是我的浮动按钮:
class ActionControls extends StatelessWidget {
Widget _iconButton({
@required BuildContext context,
@required IconData icon,
@required Function function,
Color color,
}) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: color == null ? Theme.of(context).accentColor : color,
),
child: IconButton(
icon: Icon(
icon,
size: 30,
color: Colors.white,
),
onPressed: function,
),
);
}
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
_iconButton(
context: context,
icon: Icons.keyboard_arrow_left,
function: () {},
),
const SizedBox(width: 10),
_iconButton(
context: context,
icon: Icons.add,
function: () {},
),
],
);
}
}
这是我的 FloatingActionButtonAnimator:
class NoScalingAnimation extends FloatingActionButtonAnimator {
@override
Offset getOffset({Offset begin, Offset end, double progress}) {
return end;
}
@override
Animation<double> getRotationAnimation({Animation<double> parent}) {
return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
}
@override
Animation<double> getScaleAnimation({Animation<double> parent}) {
return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
}
}
有问题的动画示例: https://imgur.com/a/1GQVUol
【问题讨论】:
-
你能添加一些代码示例吗?
-
@Sebastian 完成。
标签: flutter animation floating-action-button scaffold