小部件中的图像 [flutter]
Image in widget [flutter]
我想做一张卡片,几张卡片在扑。右侧是图像,左侧是信息文本。我用 CircleAvatar 测试了它,它几乎像我想要的那样工作,但我不想要一个圆圈,我想要一个方形图像。我删除了 CircleAvatar 部分并放入了一个新容器和一个 child,但我无法使用 AssetImage,我唯一可以使用的是 image.asset('.jpg')。该图像几乎比 phone 大,因为没有有效的方法来设置大小。使用 CircleAvatar 它可以工作,因为我将半径设置为大小。
当我尝试 AssetImage() vscode 时对我说我不能把它放在小部件中。
我希望你能帮助我(我认为 image.asset() 不是正确的方法)。谢谢大家
return new MaterialApp(
title: title,
home: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Card(
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Container(
child:
new CircleAvatar(
backgroundImage: new AssetImage('images/lake.jpg'),
radius: 80.0,
child: new Container(
padding: const EdgeInsets.all(0.0),
child: new Text('Sight'),
),
)
),
),
new Container(
child: new Text('long information text'),
)
],
)
],
),
)
],
),
)
);
}
}
您应该可以为您的行执行此操作:
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Sample App',
home: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Card(
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Container(
child: new Image.asset(
'images/lake.jpg',
height: 60.0,
fit: BoxFit.cover,
),
),
new Container(
child: new Text('long information text'),
),
],
),
],
),
),
],
),
),
);
}
在您的评论中找到答案!
你可以使用 ClipRRect,
new ClipRRect(
borderRadius: new BorderRadius.circular(8.0),
child: new AssetImage('images/lake.jpg')
)
你也可以这样做:
new Container(
width: 50.0,
height: 50.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new AssetImage('images/lake.jpg')
)
)),
我想做一张卡片,几张卡片在扑。右侧是图像,左侧是信息文本。我用 CircleAvatar 测试了它,它几乎像我想要的那样工作,但我不想要一个圆圈,我想要一个方形图像。我删除了 CircleAvatar 部分并放入了一个新容器和一个 child,但我无法使用 AssetImage,我唯一可以使用的是 image.asset('.jpg')。该图像几乎比 phone 大,因为没有有效的方法来设置大小。使用 CircleAvatar 它可以工作,因为我将半径设置为大小。 当我尝试 AssetImage() vscode 时对我说我不能把它放在小部件中。 我希望你能帮助我(我认为 image.asset() 不是正确的方法)。谢谢大家
return new MaterialApp(
title: title,
home: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Card(
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Container(
child:
new CircleAvatar(
backgroundImage: new AssetImage('images/lake.jpg'),
radius: 80.0,
child: new Container(
padding: const EdgeInsets.all(0.0),
child: new Text('Sight'),
),
)
),
),
new Container(
child: new Text('long information text'),
)
],
)
],
),
)
],
),
)
);
} }
您应该可以为您的行执行此操作:
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Sample App',
home: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Card(
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Container(
child: new Image.asset(
'images/lake.jpg',
height: 60.0,
fit: BoxFit.cover,
),
),
new Container(
child: new Text('long information text'),
),
],
),
],
),
),
],
),
),
);
}
在您的评论中找到答案!
你可以使用 ClipRRect,
new ClipRRect(
borderRadius: new BorderRadius.circular(8.0),
child: new AssetImage('images/lake.jpg')
)
你也可以这样做:
new Container(
width: 50.0,
height: 50.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new AssetImage('images/lake.jpg')
)
)),