Answers for "flutter iconbutton onpressed change icon"

0

flutter change the icon of icon button on pressed

bool selected = true;

//...

Widget build(BuildContext context) {
	return Scaffold(
    	body: Center(
          child: IconButton(
              icon: Icon( selected ? Icons.celebration : Icons.title),
              onPressed: () {
                setState(() {
                  selected = !selected;
                });
              },
          ), //IconButton
   		), //Center
    ); //Scaffold
}
Posted by: Guest on March-24-2021
0

flutter IconButton change color onPressed

class SomeState extends State<StatefulWidget> {
  Color _iconColor = Colors.white;

  @override
  Widget build(BuildContext) {
    return ListTile(
      leading: new IconButton(
        icon: Icon(Icons.star, color: _iconColor),
        onPressed: () {
          setState(() {
          _iconColor = Colors.yellow;
        });
      },
    );
  }
}
Posted by: Guest on August-12-2021

Browse Popular Code Answers by Language