Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter, remove FAB scaling animation

When page is loaded at first, FAB always do scaling animation stuff by default.

How to remove/disable Floating Action Button scaling animation

what I have done already is

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

and this is not working the above code is also refered from other question

like image 512
dontknowhy Avatar asked Oct 28 '25 03:10

dontknowhy


1 Answers

Actually, when a page is first loaded, the FAB does not animate. But if you remove the FAB (by setting: floatingActionButton: null) and/or bring it back, it animates. If your business logic permits, maybe use Offstage or Visibility widget, to "hide" the FAB instead of removing it. This way, it will disappear and appear instantly.

Another possible solution is, you don't have to use FAB widget, you can pass any widget to floatingActionButton property, like an IconButton or whatever, so really, anything is possible. :D

like image 114
user1032613 Avatar answered Oct 29 '25 16:10

user1032613



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!