How do I achieve this effect? I wanted to expand my AppBar after clicking on the dates.
Expandable AppBar (onPressed)
Asked Answered
The simplest way is to bring toggle a veriable then change the height of the bottom
widget.
Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: [IconButton(icon: Icon(Icons.place),onPressed: (){
setState((){
isOpen = !isOpen;
});
})],
bottom: PreferredSize(child: isOpen? Container(color:Colors.red, height: 100):Container(),preferredSize:Size.fromHeight(isOpen? 100:0) ,)
),)
Ok, at first sight it seems like this will work. Just one last question: can you animate those changes? For example the opening/closing of the "bottom" property. (I am new to Flutter, please bear with me :D) –
Chivalry
Yes you can. But it is a bit complicated if you're not familiar with
Animations
. If you're familiar with it you only have to 100*animation.value
for the height –
Hebdomadal I was still testing if this will do, there you go :) –
Chivalry
@ConstantinN. This works good But I want to change the action's Icon respectively when isOpen =true? How to achieve this ? –
Righthander
IconButton(icon: isOpen?Icons.pause:Icons.play) –
Hebdomadal
© 2022 - 2024 — McMap. All rights reserved.
SliverAppBar
to achieve this. – GreenSliverAppBar
allow you to disable the scroll? Because I do not want to expand/collapse theAppBar
with scrolling. – Chivalry