flutter - 为 Circle Avatar 小部件 overflow hidden (Flutter)

标签 flutter

我需要将图标放入 CircleAvatar Widget 以允许用户上传他的图像​​。

像这样:

enter image description here

这是我的代码:

child: CircleAvatar(
  child: Stack(
    children: <Widget>[
      Positioned(
        bottom: 0,
        right: 0,
        left: 0,
        height: 33,
        child: Container(
          height: 20,
          width: 30,
          color: Color.fromRGBO(0, 0, 0, .74),
          child: Center(
            child:
                Icon(Icons.photo_camera, color: Colors.grey),
          ),
        ),
      )
    ],
  ),
  radius: 68.0,
  backgroundImage:
      NetworkImage('https://via.placeholder.com/300'),
  backgroundColor: Colors.transparent,
)

但我有这样的结果:

enter image description here

带有相机图标的内部框从父小部件 (CircleAvatar) 溢出;

最佳答案

你想要的可以简单地用 - ClipOval

您的代码:

body: Center(
        child: CircleAvatar(
          child: ClipOval(
            child: Stack(
              children: <Widget>[
                Image.network('https://via.placeholder.com/300'),
                Positioned(
                  bottom: 0,
                  right: 0,
                  left: 0,
                  height: 33,
                  child: GestureDetector(
                    onTap: (){
                      print('upload Clicked');
                    },
                    child: Container(
                      height: 20,
                      width: 30,
                      color: Color.fromRGBO(0, 0, 0, .74),
                      child: Center(
                        child: Icon(Icons.photo_camera, color: Colors.grey),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          radius: 68.0,
          // backgroundImage: NetworkImage('https://via.placeholder.com/300'),
          backgroundColor: Colors.transparent,
        ),
      ),

输出: enter image description here

关于flutter - 为 Circle Avatar 小部件 overflow hidden (Flutter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56695254/

相关文章:

dart - 如何使用 android_intent 通过 flutter 打开位置设置

ios - 错误 : Build input file cannot be found: '/Users/GoogleService-Info.plist' (in target 'Runner' from project 'Runner' )

flutter - 访问 API 响应并在单击按钮时打印它?

ios - 此应用目前无法使用 Facebook 登录

flutter - 函数必须有明确的参数列表

dart - Flutter desktop/go-flutter-desktop Windows 平台打开Excel文件

flutter - 通过 Telegram Bot 发送错误消息Flutter

file - 如何复制内存中的文件?

flutter - 不处理流,而是将计数器流的值重置为0并再次收听

flutter - 提供商 : How can I `notifyListener()` within a `StreamBuilder()` ? 它导致错误 `setState() or markNeedsBuild() called during build`