Skip to content

Commit 8da4bbb

Browse files
committed
Added setState function to change state of button clicked
1 parent bcc361d commit 8da4bbb

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

building_layouts/lib/main.dart

+15-13
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,22 @@ class FavoriteWidget extends StatefulWidget{
100100

101101
class FavoriteWidgetState extends State<FavoriteWidget>{
102102

103-
bool isFavorite = false;
103+
bool isFavorite = true;
104104
int count = 41;
105105

106106
@override
107107
Widget build(BuildContext context) {
108-
// TODO: implement build
108+
109109
return Container(
110110
child: Row(
111-
children: <Widget>[
111+
mainAxisSize: MainAxisSize.min,
112+
crossAxisAlignment: CrossAxisAlignment.center,
113+
children: [
112114
IconButton(
113115
onPressed: setFavorite,
114116
icon: IconButton(
115-
icon: (isFavorite ? Icon(Icons.star) : Icon(Icons.star_border)),
116117
color: Colors.red,
118+
icon: (isFavorite ? Icon(Icons.star) : Icon(Icons.star_border)),
117119
),
118120
),
119121
Text('$count')
@@ -124,15 +126,15 @@ class FavoriteWidgetState extends State<FavoriteWidget>{
124126
}
125127

126128
void setFavorite(){
127-
128-
print("click");
129-
if(isFavorite){
130-
isFavorite = false;
131-
count = 40;
132-
}else{
133-
isFavorite = true;
134-
count = 41;
135-
}
129+
setState(() {
130+
if(isFavorite){
131+
isFavorite = false;
132+
count = 40;
133+
}else{
134+
isFavorite = true;
135+
count = 41;
136+
}
137+
});
136138
}
137139

138140
}

0 commit comments

Comments
 (0)