Flutter 调整容器大小?
我是个新手,我试图改变一个容器的大小,但即使我改变高度:150和宽度=150,它也不会改变,我只想让绿色屏幕显示大约1/5的屏幕,但我真的不知道如何解决这个问题。我不明白为什么,当改变容器的高度和宽度时,什么都不会改变 这是代码Flutter 调整容器大小?,flutter,dart,Flutter,Dart,我是个新手,我试图改变一个容器的大小,但即使我改变高度:150和宽度=150,它也不会改变,我只想让绿色屏幕显示大约1/5的屏幕,但我真的不知道如何解决这个问题。我不明白为什么,当改变容器的高度和宽度时,什么都不会改变 这是代码 return Container( decoration: new BoxDecoration(color: Colors.white), child: new MaterialApp( title: "Sample&q
return Container(
decoration: new BoxDecoration(color: Colors.white),
child: new MaterialApp(
title: "Sample",
debugShowCheckedModeBanner: false,
home: Container(
height: 150.0,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
)),
child: Stack(
children: [
Positioned(
top: 150,
left: 0,
child: Row(
children: <Widget>[
SvgPicture.asset(
user,
width: 60,
height: 60,
),
SizedBox(
width: 10,
),
Text(
"Welcome back, $username",
style: TextStyle(
fontSize: 20,
fontFamily: fontRegular,
decoration: TextDecoration.none,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
SvgPicture.asset(
"assert\\dollar.svg",
height: 25,
width: 25,
),
Text(
'$coinValue',
style: TextStyle(
fontSize: 18,
color: Colors.black,
decoration: TextDecoration.none),
),
],
),
),
SizedBox(
width: 13,
),
],
),
),
],
),
),
),
);
}
返回容器(
装饰:新盒子装饰(颜色:彩色。白色),
孩子:新材料pp(
标题:“样本”,
debugShowCheckedModeBanner:false,
家庭:集装箱(
高度:150.0,
装饰:盒子装饰(
颜色:颜色。绿色,
borderRadius:仅限borderRadius(
左下角:半径。圆形(30),
右下角:半径。圆形(30),
)),
子:堆栈(
儿童:[
定位(
排名:150,
左:0,,
孩子:排(
儿童:[
SvgPicture.asset(
使用者
宽度:60,
身高:60,
),
大小盒子(
宽度:10,
),
正文(
“欢迎回来,$username”,
样式:TextStyle(
尺寸:20,
fontFamily:fontRegular,
装饰:textEdition.none,
颜色:颜色,白色,
),
),
大小盒子(
宽度:10,
),
容器(
填充:常数边集全部(5.0),
装饰:盒子装饰(
边框:边框。全部(宽度:1.5,颜色:颜色。黑色),
颜色:颜色。来自RGBO(230,230,230,1),
边界半径:边界半径。圆形(30),
),
孩子:排(
儿童:[
SvgPicture.asset(
“assert\\dollar.svg”,
身高:25,
宽度:25,
),
正文(
“$coinValue”,
样式:TextStyle(
尺码:18,
颜色:颜色,黑色,
装饰:文本装饰。无),
),
],
),
),
大小盒子(
宽度:13,
),
],
),
),
],
),
),
),
);
}
这是结果
我只想要这样的东西
您的
容器
小部件中有堆栈
小部件。这就是它占据整个屏幕的原因。尝试删除堆栈
小部件
return Container(
decoration: new BoxDecoration(color: Colors.white),
child: new MaterialApp(
title: "Sample",
debugShowCheckedModeBanner: false,
home: Container(
height: 150.0,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
)),
child: Positioned(
top: 150,
left: 0,
child: Row(
children: <Widget>[
SvgPicture.asset(
user,
width: 60,
height: 60,
),
SizedBox(
width: 10,
),
Text(
"Welcome back, $username",
style: TextStyle(
fontSize: 20,
fontFamily: fontRegular,
decoration: TextDecoration.none,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
SvgPicture.asset(
"assert\\dollar.svg",
height: 25,
width: 25,
),
Text(
'$coinValue',
style: TextStyle(
fontSize: 18,
color: Colors.black,
decoration: TextDecoration.none),
),
],
),
),
SizedBox(
width: 13,
),
),
],
),
),
),
);
返回容器(
装饰:新盒子装饰(颜色:彩色。白色),
孩子:新材料pp(
标题:“样本”,
debugShowCheckedModeBanner:false,
家庭:集装箱(
高度:150.0,
装饰:盒子装饰(
颜色:颜色。绿色,
borderRadius:仅限borderRadius(
左下角:半径。圆形(30),
右下角:半径。圆形(30),
)),
孩子:定位(
排名:150,
左:0,,
孩子:排(
儿童:[
SvgPicture.asset(
使用者
宽度:60,
身高:60,
),
大小盒子(
宽度:10,
),
正文(
“欢迎回来,$username”,
样式:TextStyle(
尺寸:20,
fontFamily:fontRegular,
装饰:textEdition.none,
颜色:颜色,白色,
),
),
大小盒子(
宽度:10,
),
容器(
填充:常数边集全部(5.0),
装饰:盒子装饰(
边框:边框。全部(宽度:1.5,颜色:颜色。黑色),
颜色:颜色。来自RGBO(230,230,230,1),
边界半径:边界半径。圆形(30),
),
孩子:排(
儿童:[
SvgPicture.asset(
“assert\\dollar.svg”,
身高:25,
宽度:25,
),
正文(
“$coinValue”,
样式:TextStyle(
尺码:18,
颜色:颜色,黑色,
装饰:文本装饰。无),
),
],
),
),
大小盒子(
宽度:13,
),
),
],
),
),
),
);
您的容器
小部件中有堆栈
小部件。这就是它占据整个屏幕的原因。尝试删除堆栈
小部件
return Container(
decoration: new BoxDecoration(color: Colors.white),
child: new MaterialApp(
title: "Sample",
debugShowCheckedModeBanner: false,
home: Container(
height: 150.0,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
)),
child: Positioned(
top: 150,
left: 0,
child: Row(
children: <Widget>[
SvgPicture.asset(
user,
width: 60,
height: 60,
),
SizedBox(
width: 10,
),
Text(
"Welcome back, $username",
style: TextStyle(
fontSize: 20,
fontFamily: fontRegular,
decoration: TextDecoration.none,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
SvgPicture.asset(
"assert\\dollar.svg",
height: 25,
width: 25,
),
Text(
'$coinValue',
style: TextStyle(
fontSize: 18,
color: Colors.black,
decoration: TextDecoration.none),
),
],
),
),
SizedBox(
width: 13,
),
),
],
),
),
),
);
返回容器(
装饰:新盒子装饰(颜色:彩色。白色),
孩子:新材料pp(
标题:“样本”,
debugShowCheckedModeBanner:false,
家庭:集装箱(
高度:150.0,
装饰:盒子装饰(
颜色:颜色。绿色,
borderRadius:仅限borderRadius(
左下角:半径。圆形(30),
右下角:半径。圆形(30),
)),
home: Scaffold(
body: SafeArea(
child: Container(
height: 150.0,
decoration: BoxDecoration(
color: Colors.green,
),
child: Row(
children: <Widget>[
SizedBox(
width: 10,
),
Text(
"Welcome back",
style: TextStyle(
fontSize: 20,
//fontFamily: fontRegular,
decoration: TextDecoration.none,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
Text(
'dsfsfsf',
style: TextStyle(
fontSize: 18,
color: Colors.black,
decoration: TextDecoration.none),
),
],
),
),
SizedBox(
width: 13,
),
],
),
),
),
),
Container(
height: 150,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(20),
bottomLeft: Radius.circular(20))),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 30.0,
backgroundImage: NetworkImage('https://via.placeholder.com/150'),
backgroundColor: Colors.transparent,
),
Expanded(child:Text("Hey there, Welcome back LQK!")),
Container(
width:100,
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
Icon(Icons.search) //put your desired icon here
],
),
),
],
)