【问题标题】:Flutter, remove FAB scaling animationFlutter,去除 FAB 缩放动画
【发布时间】:2021-12-10 13:47:22
【问题描述】:

第一次加载页面时,FAB 总是默认做缩放动画。

如何移除/禁用浮动操作按钮缩放动画

我已经做的是

return Scaffold(
      floatingActionButtonAnimator: AnimationNoScaling(),

...


import 'package:flutter/material.dart';

class AnimationNoScaling extends FloatingActionButtonAnimator{
  double? _x;
  double? _y;
  @override
  Offset getOffset({Offset? begin, Offset? end, double? progress}) {
    _x = begin!.dx +(end!.dx - begin.dx)*progress!;
    _y = begin.dy +(end.dy - begin.dy)*progress;
    return Offset(_x!,_y!);
  }

  @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!);
  }
}

这不起作用,上面的代码也参考了其他问题

【问题讨论】:

  • 这能回答你的问题吗? Disable Scaffold FAB animation
  • @AdityaDees 如果您查看代码,您会注意到 OP 实际上使用了该答案中的代码。
  • 我认为需要添加更多细节,关于 dart 和 Flutter 的版本

标签: flutter flutter-layout flutter-animation


【解决方案1】:

实际上,当第一次加载页面时,FAB 并没有动画。但是,如果您删除 FAB(通过设置:floatingActionButton: null)和/或将其带回,它会生成动画。如果您的业务逻辑允许,可以使用OffstageVisibility 小部件来“隐藏”FAB 而不是删除它。这样,它会立即消失并立即出现。

另一个可能的解决方案是,您不必必须使用 FAB 小部件,您可以将任何小部件传递给 floatingActionButton 属性,例如 IconButton 或其他任何东西,所以真的,一切皆有可能. :D

【讨论】:

  • 好像有先决条件。以标签栏作为第一页加载时没有动画。但是,如果您转到另一个选项卡索引,然后返回该页面,则会出现动画。我将 Container 作为参数值而不是 FAB。结果是一样的。
猜你喜欢
  • 1970-01-01
  • 2019-05-03
  • 2020-04-28
  • 2018-12-30
  • 1970-01-01
  • 1970-01-01
  • 2018-02-07
  • 2014-06-12
  • 1970-01-01
相关资源
最近更新 更多