Problems encountered when flutter uses RepaintBoundary to save Widget to picture to album

The Widget displayed on the page has rounded corners. At this time, after saving the converted picture of the Widget to the album, it is found that there will be black on the outside of the rounded corners, as shown in the figure:

After asking ui to save a picture with rounded corners to the album, I found that this problem still exists. Therefore, the picture saved to the album is considered to be a right-angled picture, but the picture displayed on the page is still rounded.

I wrote a right-angled Widget separately but didn't reference it on the page, and found that RepaintBoundary only works on the Widget displayed on the page.

Here is an idea for my solution: If Positioned positioning is not used in the Stack component, the components will overlap together, so we can scale down the right-angled Widget to be saved as a picture, and hide it behind the rounded-cornered Widget that needs to be displayed on the page .

Stack(
    alignment: Alignment.center,
    children: [
        //需要保存至相册的直角Widget,等比例缩小
        RepaintBoundary(
            key: globalKey,
            child: Container(
                ...
            )
        ),
        //展示在页面的圆角Widget
        Container(
            ...
        )
    ],
)

Guess you like

Origin blog.csdn.net/YML_426/article/details/128673786