我正在try 创建一个圆形图像.不幸的是,集装箱的宽度没有得到认可,我不明白为什么.我错过了什么?

enter image description here

Drawer _getDrawer(List<Job> data) {
  return Drawer(
    // Add a ListView to the drawer. This ensures the user can scroll
    // through the options in the Drawer if there isn't enough vertical
    // space to fit everything.
    child: ListView(
      // Important: Remove any padding from the ListView.
      padding: EdgeInsets.zero,
      children: <Widget>[
        _getDrawerHeader(),
        ListTile(
          title: Text('Item 1'),
          onTap: () {
            // Update the state of the app
            // ...
          },
        ),
        ListTile(
          title: Text('Item 2'),
          onTap: () {
            // Update the state of the app
            // ...
          },
        ),
      ],
    ),
  );
}

DrawerHeader _getDrawerHeader() {
  return DrawerHeader(
    child: StreamBuilder(
        stream: FirebaseAuth.instance.currentUser().asStream(),
        builder: (context, AsyncSnapshot<FirebaseUser> snapshot) {
          if (snapshot.hasData) {
            return ListView(
              children: <Widget>[
                _getCircleImage(snapshot.data.photoUrl),
                Text('test'),
                Text('test'),
              ],
            );
          }
          return Center(child: CircularProgressIndicator());
        }),
    decoration: BoxDecoration(
      color: Colors.blue,
    ),
  );
}

_getCircleImage(String url) {
  return Container(
    width: 64.0,
    height: 64.0,
    decoration: new BoxDecoration(
      image: new DecorationImage(
        image: new NetworkImage(url),
        fit: BoxFit.cover,
      ),
      shape: BoxShape.circle,
    ),
  );
}

推荐答案

这有点棘手,但这是Flutter 的工作原理,你的Container不知道家长的限制,然后它试图填补所有可用的空间.

您可以通过添加Align个小部件来解决此问题

    _getCircleImage(String url) {
      return Align(
        alignment: Alignment.centerLeft,
        child: Container(
          width: 64.0,
          height: 64.0,
          decoration: new BoxDecoration(
            image: new DecorationImage(
              image: new NetworkImage(url),
              fit: BoxFit.cover,
            ),
            shape: BoxShape.circle,
          ),
        ),
      );
    }

更多信息:https://docs.flutter.io/flutter/widgets/Container-class.html

Flutter相关问答推荐

为什么小部件会在其父文件中重建,但放在单独文件中时却不会重建?

修复容器`Text`和容器表单之间的重叠

Flutter 中不存在URI的目标

如何在Flutter 中播放音频

如何在Ffltter Chrome应用程序中使用webview_fltter_web显示自定义html而不是外部uri?

CLI数据库连接后将SHA-1密钥添加到Firebase项目

为什么当我使用Riverpod更新状态时,列表会被刷新?

确保通过在CheckIfFavoriteMovieEvent((event,emit){...})上注册处理程序误差

将列表<;Events>;从Flutter 应用程序中的函数传回EventLoader属性时出错

如何在Flutter 安全存储器中存储对象值?

Firestore 不会取代 map

在 Dart 中按土耳其语字母顺序对字符串进行排序

在使用 Android 12+ 的真实 Android 设备上,SingleChildScrollView 中最初位于视口之外的无响应 Web 视图

Flutter:如何在现有布局之上显示圆角布局?

网页浏览器不支持鼠标滚动的行项目

Flutter底部面板局部显示

Flutter 自定义对齐

将状态维护到 asyncNotifier

Flutter 中的 Firebase 后台消息处理程序产生重复的隔离并运行应用程序两次

如何在Flutter 中制作自定义微调器?