Flutter:居中的 CircleAvatar 旁边的位置图标

Flutter: Position Icon next to a centered CircleAvatar

我想在居中的圆形头像旁边的右上角放置一个编辑图标。但是,如果我在 Row Widget 中使用 Center Widget,它就不起作用:

Row(
              children: <Widget>[
                Center(
                  child:
                CircleAvatar(
                  radius: 70,
                  backgroundImage: NetworkImage(
                      ""),
                ),
                ),
                Icon(Icons.edit),
              ],
            )

如果我使用 mainaxisalignment 将行内容居中,它不会使头像居中,而是头像与图标一起居中:

Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                CircleAvatar(
                  radius: 70,
                  backgroundImage: NetworkImage(
                      "https://autix.ch/wp-content/uploads/profile-placeholder.png"),
                ),
                Icon(Icons.edit),
              ],
            ),

It should look like this:

尝试使用堆栈:

Container(
  width: 200,
  height: 200,
  child: Stack(
    children: <Widget>[
      Align(
        alignment: Alignment.topRight,
        child: Icon(Icons.access_time),
      ),
      Container(
        width: 200,
        height: 200,
        child: CircleAvatar(
          child: Text('Avatar'),
        ),
      ),
    ],
  ),
),

结果:

您可以使用容器小部件包裹编辑图标,并将其与右上角对齐,如下所示:

Container(
   height: 140,
   alignment: Alignment.topRight,
   child: Icon(Icons.edit),
),

不用容器也可以:

CircleAvatar(
  backgroundImage: NetworkImage(photoURL),
  child: Stack(
    children: [
      Align(
        alignment: Alignment.topRight,
        child: Icon(Icons.ac_unit),
      )
    ],
  ),
),