Android studio 颤振-如何使用容器小部件与图像和文本/图标下面的图像
在Flatter的容器中,我在尝试创建图像和该图像下的文本/图标时遇到了一点问题。我想在图像下包括三行小部件,每行都有一个文本小部件或图标小部件,但每当我尝试这样做时,容器就会变成文本/图标小部件的形状,图像就会消失。在这种情况下,我是否使用了错误的小部件?我想有一些类似的注意与标题,日期和位置的图片底部部分 我的代码:Android studio 颤振-如何使用容器小部件与图像和文本/图标下面的图像,android-studio,user-interface,dart,widget,flutter,Android Studio,User Interface,Dart,Widget,Flutter,在Flatter的容器中,我在尝试创建图像和该图像下的文本/图标时遇到了一点问题。我想在图像下包括三行小部件,每行都有一个文本小部件或图标小部件,但每当我尝试这样做时,容器就会变成文本/图标小部件的形状,图像就会消失。在这种情况下,我是否使用了错误的小部件?我想有一些类似的注意与标题,日期和位置的图片底部部分 我的代码: class EventRow extends StatelessWidget { @override Widget build(BuildContext context
class EventRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 150.0,
margin: const EdgeInsets.symmetric(
vertical: 16.0,
horizontal: 24.0,
),
child: new Stack(
children: <Widget>[
eventCardContent,
userThumbnail,
],
),
);
}
final userThumbnail = new Container(
margin: EdgeInsets.symmetric(vertical: 16.0),
alignment: FractionalOffset.centerLeft,
child: CircleAvatar(
backgroundImage: AssetImage("assets/images/letter_u.png"),
backgroundColor: Colors.white,
maxRadius: 40.0,
),
);
final eventCardContent = new Container(
margin: new EdgeInsets.only(left: 46.0),
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
color: new Color(0xFFFFFFFF),
borderRadius: new BorderRadius.circular(8.0),
image: DecorationImage(
image: AssetImage("assets/images/moon_pumpkin.jpeg"),
fit: BoxFit.fill,
),
),
);
class EventRow扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回容器(
高度:150.0,
边距:常量边集。对称(
垂直线:16.0,
水平:24.0,
),
子:新堆栈(
儿童:[
事件内容,
用户缩略图,
],
),
);
}
最终用户缩略图=新容器(
边缘:边缘组。对称(垂直:16.0),
对齐:分数偏移。左中,
孩子:圆环星(
背景图片:AssetImage(“assets/images/letter_.png”),
背景颜色:Colors.white,
最大半径:40.0,
),
);
最终事件cardcontent=新容器(
边距:仅限新边集(左:46.0),
装饰:新盒子装饰(
形状:BoxShape.rectangle,
颜色:新颜色(0xFFFFFF),
边界半径:新边界半径。圆形(8.0),
图像:装饰图像(
图片:AssetImage(“assets/images/moon_pumpking.jpeg”),
fit:BoxFit.fill,
),
),
);
您需要将userThumbnail的容器包装为Column并使用属性mainAxisSize:mainAxisSize.min,这就解决了您的问题
它告诉column widget占用空间任何所需的空间,但不要超过这个空间。任何
大小的不确定性不适用于mainAxisSize:mainAxisSize.min
,并可能导致未定义大小的ui错误
下面的代码可能对您有所帮助
@override
Widget build (BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text("Csd"),
),
body: Column(
children: <Widget>[
Container(
height: 150.0,
margin: const EdgeInsets.symmetric(
vertical: 16.0,
horizontal: 24.0,
),
child: new Stack(
children: <Widget>[
eventCardContent,
userThumbnail,
],
),
),
new Column(
children: <Widget>[
Row(
children: <Widget>[
new Column(
children: <Widget>[
Text("SEP"),
Text("30"),
],
),
Expanded(
child:new Column(
children: <Widget>[
new Text("title"),
new Text("Sub title"),
new Text("Second Sub Title"),
],
)
)
],
),
],
)
],
),
);
}
@覆盖
小部件构建(构建上下文){
返回脚手架(
appBar:新的appBar(
标题:新文本(“Csd”),
),
正文:专栏(
儿童:[
容器(
高度:150.0,
边距:常量边集。对称(
垂直线:16.0,
水平:24.0,
),
子:新堆栈(
儿童:[
事件内容,
用户缩略图,
],
),
),
新专栏(
儿童:[
划船(
儿童:[
新专栏(
儿童:[
文本(“SEP”),
文本(“30”),
],
),
扩大(
子:新列(
儿童:[
新文本(“标题”),
新文本(“子标题”),
新文本(“第二子标题”),
],
)
)
],
),
],
)
],
),
);
}
您能添加一张您希望屏幕外观的图像吗?我有一些想法,但需要确切地了解您的目标外观。我刚刚对原始问题进行了更新,但这并不是我想要实现的,我对问题进行了更新以澄清。