Flutter:如何在 CircleAvatar 上放置图标并将其居中?

标签 flutter dart icons center

enter image description here
我想将相机图标居中,但我做不到。我尝试使用图像而不是图标,但这仍然无效。我认为它不起作用,因为不可能在 CircleAvatar 上放置图标,但必须有办法做到这一点。
这是我的代码:

    return SizedBox(
      height: 115,
      width: 115,
      child: Stack(
        clipBehavior: Clip.none,
        fit: StackFit.expand,
        children: [
          CircleAvatar(
            backgroundImage: AssetImage("assets/images/Profile Image.png"),
          ),
          Positioned(
              right: -16,
              bottom: 0,
              child: SizedBox(
                  height: 46,
                  width: 46,
                  child: FlatButton(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(50),
                      side: BorderSide(color: Colors.white),
                    ),
                    color: Color(0xFFF5F6F9),
                    onPressed: () {},
                    // TODO: Icon not centered.
                    child: Center(child: Icon(Icons.camera_alt_outlined)),
                  )))
        ],
      ),
    );

最佳答案

Widget build(BuildContext context) {
    return SizedBox(
      height: 115,
      width: 115,
      child: Stack(
        clipBehavior: Clip.none,
        fit: StackFit.expand,
        children: [
          CircleAvatar(
            backgroundImage: AssetImage("assets/images/Profile Image.png"),
          ),
          Positioned(
              bottom: 0,
              right: -25,
              child: RawMaterialButton(
                onPressed: () {},
                elevation: 2.0,
                fillColor: Color(0xFFF5F6F9),
                child: Icon(Icons.camera_alt_outlined, color: Colors.blue,),
                padding: EdgeInsets.all(15.0),
                shape: CircleBorder(),
              )),
        ],
      ),
    );
  }
我已经删除了 SizedBox 并使用了 RawMaterialButton 代替。

关于Flutter:如何在 CircleAvatar 上放置图标并将其居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66953044/

相关文章:

android - 在 Flutter 中使用延迟重绘小部件

icons - 网站的书签图标

flutter - 失败 : Build failed with an exception.( flutter )

dart - Flutter 在后台运行 websocket?

Flutter 2 - 如何在新的 TextButton 中制作圆角并给它一个高度

html - 图标 map (或图表)如何工作?

Android Studio 矢量资源失真

flutter audio_service 和 just_audio 不适用于 ios

flutter - 如何在flutter中比较两个列表数据( Dart )

Dart polymer : unable to get input from array