如何制作一个带有按钮的图像图标来像谷歌一样更改图像:

3 icons image dart flutter flutter-layout

我想在我的个人资料屏幕中创建一个带有按钮的用户个人资料照片,或者创建一些创意来更改此照片,例如谷歌:

谷歌

但我现在拥有的是这样的:

CircleAvatar(
  radius: 75,
  backgroundColor: Colors.grey.shade200,
  child: CircleAvatar(
    radius: 70,
    backgroundImage: AssetImage('assets/images/default.png'),
  )
),
Run Code Online (Sandbox Code Playgroud)

如何添加像谷歌示例中那样的按钮?

RaS*_*Sha 6

使用Stack您可以将图标放在头像顶部的特定位置。

Stack(
      children: [
        CircleAvatar(
          radius: 75,
          backgroundColor: Colors.grey.shade200,
          child: CircleAvatar(
            radius: 70,
            backgroundImage: AssetImage('assets/images/default.png'),
          ),
        ),
        Positioned(
          bottom: 1,
          right: 1,
          child: Container(
            child: Padding(
              padding: const EdgeInsets.all(2.0),
              child: Icon(Icons.add_a_photo, color: Colors.black),
            ),
            decoration: BoxDecoration(
                border: Border.all(
                  width: 3,
                  color: Colors.white,
                ),
                borderRadius: BorderRadius.all(
                  Radius.circular(
                    50,
                  ),
                ),
                color: Colors.white,
                boxShadow: [
                  BoxShadow(
                    offset: Offset(2, 4),
                    color: Colors.black.withOpacity(
                      0.3,
                    ),
                    blurRadius: 3,
                  ),
                ]),
          ),
        ),
      ],
    )
Run Code Online (Sandbox Code Playgroud)