Home > Mobile >  Flutter AnimatedContainer on ListView inside FutureBuilder doens't work
Flutter AnimatedContainer on ListView inside FutureBuilder doens't work

Time:09-30

I'm trying to change the size on hover. The future build is a function on initstate. I'm building an WebProject, and on hover anything change

My widget tree:

FutureBuilder<List<Repo>>(
      future: receberDados,
      builder: (context, snap) {
        if (snap.connectionState == ConnectionState.done) {
          var repos = snap.data;
          return Container(
            height: 350,
            child: ListView.builder(
                scrollDirection: Axis.horizontal,
                itemCount: repos!.length,
                itemBuilder: (context, i) {
                  var hover = true;
                  return MouseRegion(
                    onEnter: (mouse) {
                      setState(() {
                        hover = true;
                      });
                      print(hover);
                    },
                    onExit: (mouse) {
                      setState(() {
                        hover = false;
                      });
                      print(hover);
                    },
                    child: AnimatedContainer(
                      duration: Duration(seconds: 1),
                      curve: Curves.bounceIn,
                      height: hover ? 320 : 300,
                      width: hover ? 470 : 450,
                      margin: EdgeInsets.all(5),
                      decoration: BoxDecoration(
                          color: hover ? Colors.red : Colors.black,
                          border: Border.all(
                            color: Colors.white70,
                          ),
                          borderRadius: BorderRadius.circular(20)),
                      padding: EdgeInsets.all(10),
                      child:

Is my first time with web Develop with Flutter. Need something extra?

CodePudding user response:

Try using a StatefulBuilder wrapping your AnimatedContainer, it seems that the hover variable it's not updating your AnimatedContainer. Something Like this :

child: StatefulBuilder(
       builder: (BuildContext context, StateSetter setState) {
       return AnimatedContainer(
                  duration: Duration(seconds: 1),
                  curve: Curves.bounceIn,
                  height: hover ? 320 : 300,
                  width: hover ? 470 : 450,
                  margin: EdgeInsets.all(5),
                  decoration:

Hope i could be of any help :)

I suggest you edit your question with the full code of FutureBuilder<List<Repo>> for better understanding of your code.

  • Related