How can i make the icon change when it is clicked - flutter

I want the arrow to change and display the visibility widget when about me is clicked on the image.

About your attached image, you can simply get the effect using ExpansionTile.
How-ever to change icon based on click
create a bool _isExpanded = false inside state class.
On expand changes, use setstate to change the value.
Using assigning the icon
Icon(_isExpanded?
Icons.arrow_downward
:Icons.arrow_upward,
),

int angle = 0;
RotatedBox(
quarterTurns: angle,
child: IconButton(
icon: Icon(Icons.arrow_forward_ios),
onPressed: () {
setState(() {
angle = 1;
});
},
),
),

Related

How to create dropdow widget when click on button?

image description here
so how to create it? I tried to find out but still can't find a way
You can simply use a dropdown widget and wrap it with visibility widget which will be updated on the basis of that button click:
bool visible=false;
ElevatedButton(onPressed: (){
visible=!visible; //onPressing the click button it will update visible variable
}, child: Text('Click')),
Visibility(
visible: visible, //which will make the dropdown visible
child: DropdownButton(items: items, onChanged: (){}))
Make use of Visibility widget
bool isDropDownVisible = false
Visibility(
visible: isDropDownVisible,
child: DropdownButton(
// DropDown Code
)
Now while onButtonClick set it as a below:
setState(() {
isCheckSelected =! isCheckSelected;
});

In Flutter, how to enable and disable a button by clicking on another button?

I have two elevated buttons inside a Row widget. When I press Button 1, I want to disable Button 2 and when I press Button 1 again I want to enable Button 2. I have searched everywhere but I can't seem to find an answer. I am hoping someone can point me in the right direction.
You could use onPressed : null for disabled button 2.
Use boolean variable for set disable and enable.
var isDisable=true;
This is the button 1 widget and it uses setButton() method for enable and disable button 2.
//button 1
RaisedButton(
padding: const EdgeInsets.all(20),
textColor: Colors.white,
color: Colors.green,
onPressed: (){
setState((){
setButton();
});
},
child: Text('Button 1'),
)
This is the button 2 widget and we check the boolean variable ( isDisable) to check the enable and disable state in button 2.
// button 2
RaisedButton(
padding: const EdgeInsets.all(20),
textColor: Colors.white,
color: Colors.green,
onPressed: isDisable
? () => null : clickButton(),
child: Text('Button 2'),
)
This is a method that uses to change boolean variable value for enable and disable button 2.
//Method for enable and disable button2
void setButton(){
if(isDisable){
isDisable = false;
}else{
isDisable = true;
}
}
Hope this will solve your problem!

Floating action button to be ontop of drawer after opening

I have a floating action button which opens the drawer. I want it to stay in its place when it opens the drawer and just change the icon to close icon with animation. I couldn't find a good solution to do this.
I tried wrapping inside my drawer with scaffold and adding a floating action button there and using hero widgets so make it look like it stays in its place but didn't help at all.
Is there anyway to achieve this?
U can use foldable Sidebar package to achieve this functionalities that's package is available on :
https://pub.dev/packages/foldable_sidebar
And check this piece of code how to use this :
child: Scaffold(
body: FoldableSidebarBuilder(
drawerBackgroundColor: Colors.deepOrange,
drawer: CustomDrawer(closeDrawer: (){
setState(() {
drawerStatus = FDBStatus.FDB_CLOSE; // For Closing the Sidebar
});
},),
screenContents: FirstScreen(), // Your Screen Widget
status: drawerStatus,
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.deepOrange,
child: Icon(Icons.menu,color: Colors.white,),
onPressed: () {
// To Open/Close Sidebar
setState(() {
drawerStatus = drawerStatus == FDBStatus.FDB_OPEN ? FDBStatus.FDB_CLOSE : FDBStatus.FDB_OPEN;
});
}),
),
),

Long pressed menu in flutter

how to make this top bar menu when we do a long press on a card or container.
you can wrap your card widget with InkWell or GestureDetector both have longPress, then you pass a call back to your view to show the menu.
Color _colorFilterTile = Colors.transparent;
InkWell(
onLongPress: (){
//call function
setState(() {
_colorFilterTile= Colors.green.withOpacity(0.5);
});
},
child: Container(
color: _colorFilterTile,
child: ...,
),
)

Adding keyboard functionalities to button in flutter (custom keyboard with buttons)

I can use TextFormField() widget effectively. But, some of my users may not have the characters in their keyboard that is needed in my application. So, I want to create a button (raised, flat, material does not matter) and when user taps on the button I want to add some characters that are in the FormTextField() already.
Logically code is this:
RaisedButton(
child: Text('ə'),
onPressed: (){
input = input + 'ə';
}
),
You can modify the context of a text field using a TextEditingController.
Declaration:
final _controller = TextEditingController();
Assignment:
TextField( // Or TextFormField
controller: _controller,
...
),
Usage:
RaisedButton(
child: Text('a'),
onPressed: () {
setState(() => _controller.text += 'a');
},
),