I'm trying to create an appbar that will show a second row when a action button is clicked. I've managed do to this without animations but I would like to add some animations to the appbar as it's quite jarring without it.
I'm just trying to change the size of the appbar so the appbar will expand to show a row of buttons in the bottom property. At the moment I have the following code;
import 'package:flutter/material.dart';
class AnimatedAppBar extends StatefulWidget implements PreferredSizeWidget{
final String titleText;
const AnimatedAppBar({required this.titleText});
@override
State<StatefulWidget> createState() => _AnimatedAppBarState();
@override
Size get preferredSize => Size.fromHeight(kToolbarHeight);
}
class _AnimatedAppBarState extends State<AnimatedAppBar> with SingleTickerProviderStateMixin{
late Animation<double> animation;
late AnimationController controller;
bool toggled = false;
void toggle(){
toggled ? controller.reverse() : controller.forward();
toggled = !toggled;
}
@override
void initState(){
super.initState();
controller = AnimationController(duration: const Duration(milliseconds: 100), vsync: this);
animation = Tween<double>(begin: kToolbarHeight, end: kToolbarHeight*2).animate(controller)..addListener(() {setState(() {
});});
controller.reset();
}
@override
Widget build(BuildContext context) {
return AppBar(
title: Text(widget.titleText),
toolbarHeight: animation.value,
actions: [
IconButton(
icon: const Icon(Icons.person),
onPressed: (){
toggle();
}
)
],
);
}
}
I tried to apply the height to the bottom property but this just causes the content of the appbar to move up and down inside the appbar whilst the appbar's height remains constant.