Q:

"setState" is not working for image update

I have a statefull class, and i just wanna update a image when clicked in a arrow icon, but setstate isn't working....
My statefull class:
class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
...
}

My varible with image path is here:
              Container(
                          margin: EdgeInsets.only(top: 10.0),
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: Color.fromRGBO(13, 80, 82, 0.7),
                              width: 1.0,
                            ),
                          ),
                          height: 293.0,
                          width: 130.0,
                          child: Image.asset(_avatarSelectec),
                        ),

My setState when icon is clicked:
         IconButton(
                      color: Color.fromRGBO(6, 30, 40, 0.9),
                      icon: Icon(Icons.arrow_forward_ios),
                      onPressed: () {
                        setState(() {
                              _userAvatar++;
                              _avatarSelectec = "img/avatar/free/" +_userAvatar.toString() + ".gif";
                              print(_avatarSelectec);
                              print(_userAvatar);
                            });
                          },
                        ),

I'm printting the varible with the path (_avatarSelectec) and variable with the image number (_userAvatar) both are correct in the log, but nothing happens...
I dont think this is wrong... cant see my mistake....

A:

try wrapping your Image.asset widget with ValueListenableBuilder, and make _userAvatar a ValueNotifier

