【问题标题】:How to make an Image Icon with a button to change the image like google:如何使用按钮制作图像图标以更改图像,如谷歌:
【发布时间】:2021-03-01 23:28:06
【问题描述】:

我想在我的个人资料屏幕中创建一个用户的个人资料照片,并用一个按钮进行四舍五入,或者像谷歌这样的创意来改变这张照片:

但我现在拥有的是:

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

如何添加像 google 示例中一样的按钮?

【问题讨论】:

    标签: image flutter dart icons flutter-layout


    【解决方案1】:

    您可以使用 Stack 小部件并将 Positioned 作为其子小部件。

    【讨论】:

    • 你知道如何制作圆形按钮吗?
    • 照片图标不一定是按钮。您可以使用 InkWell 包装该图像并添加 onTap() 方法以实现您在单击按钮时编写的相同功能。
    【解决方案2】:

    使用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,
                      ),
                    ]),
              ),
            ),
          ],
        )
    

    【讨论】:

      猜你喜欢
      • 2017-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多