Home > Mobile >  How to animate a Flutter widget whose position changes due to layout changes
How to animate a Flutter widget whose position changes due to layout changes

Time:11-12

I'm asking the same question as Current state

CodePudding user response:

It seems like the solution is dependent on a couple of things - one is that I had to set the resetToAvoidBottomInset property on my Scaffold widget to false, but in addition I had to use an AnimatedPadding widget that applies a padding to the bottom of my centered content that is equal to the MediaQuery.of(context).viewInsets.bottom value which accounts for space taken up by the keyboard. This certainly works but feels odd that I'm relying on knowledge of what's happening outside of the widget in order to provide an animation.

Here's a sample of the relevant code:

Expanded(
              child: Container(
                color: Colors.white,
                child: AnimatedPadding(
                  padding: EdgeInsets.only(
                      bottom: MediaQuery.of(context).viewInsets.bottom),
                  duration: const Duration(milliseconds: 600),
                  curve: Curves.easeInOut,
                  child: Center(

Desired outcome

CodePudding user response:

Just set property resizeToAvoidBottomInset in your Scaffold to false

  • Related