Search code examples
flutteranimationdrawpaint

Flutter - Custom Paint Animation disappears from screen


I have some thumbnails with a custom paint animation, and i want to show the selected animation at the main container when the user tap the thumbnail.

This part is "ok". The problem is that the custom paint disappears a few seconds after ends the animation. And i'm setting the same widget from the thumbnail to the main container, but differently of the thumbnail, the custom paint doesn't remains after the animation ends on the main container. Someone has any idea of what can be the problem?

Here is a gif with what is happening.


Solution

  • The problem was related to the same question of this answer, but I couldn't figured it out because even the thumbnails are inside the stack. And I was getting the problem even setting the width and height for the parent container of the custom paint. I solved only wrapping the entire stack with a LayoutBuilder like the code bellow:

    _buildContent() {
        var ctxSize = MediaQuery.of(context).size;
        return Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          child: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
              return Stack(
                children: <Widget>[
    
                  //Code with CustomPaint
    
                ],
              );
            },
          ),
        );
      }