【发布时间】:2019-01-16 21:14:28
【问题描述】:
我正在尝试创建一个圆形图像。不幸的是,容器的宽度没有得到尊重,我不知道为什么。我错过了什么?
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,
),
);
}
【问题讨论】:
-
图像似乎导致失真。我不知道为什么。将整个容器放入 CircleAvatar 作为一个孩子奇怪地解决了这个问题。但是直接将图像作为 backgroundImage 应用到 Circle Avatar 也不起作用。
标签: flutter