Flutter 包装在容器中时未调整卡片大小
在我的flatter应用程序中,我有一个Flutter 包装在容器中时未调整卡片大小,flutter,Flutter,在我的flatter应用程序中,我有一个GridView,其中我列出了卡片。在卡片中,我想要一个图像和一些文本。我正试着这样做: import 'package:flutter/material.dart'; class Home extends StatefulWidget{ @override State<StatefulWidget> createState() { return HomeState(); } } class HomeState exte
GridView
,其中我列出了卡片。在卡片中,我想要一个图像和一些文本。我正试着这样做:
import 'package:flutter/material.dart';
class Home extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return HomeState();
}
}
class HomeState extends State<Home>{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.green,
Colors.teal,
]
)
),
),
Padding(
padding: const EdgeInsets.only(top: 65),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.white60, width: 2.0)
),
padding: EdgeInsets.all(8),
child: CircleAvatar(
backgroundColor: Colors.white,
child: Icon(Icons.restaurant, size: 120,),
),
),
]
),
SizedBox(
height: 8,
),
Text(
"Genesis Technologies",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
color: Colors.white
),
),
SizedBox(
height: 6,
),
Text(
"Please take the following precautions",
style: TextStyle(
fontSize: 16,
color: Colors.white70
),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 350),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
)
),
),
Container(
margin: EdgeInsets.only(top: 250),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30)
)
),
child: Padding(
padding: EdgeInsets.all(0),
child: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
children: <Widget>[
Container(
height: 200,
width: 100,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(Icons.restaurant, size: 120,),
Text(
"Cover your mouth and nose when yous sneeze or cough",
style: TextStyle(
fontWeight: FontWeight.bold
),
),
],
),
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(Icons.restaurant, size: 120,),
Text(
"Avoid touching your face with unwashed hands",
style: TextStyle(
fontWeight: FontWeight.bold
),
),
],
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(Icons.restaurant, size: 120,),
Text(
"Stay home if you don't need to get out for critical matters",
style: TextStyle(
fontWeight: FontWeight.bold
),
),
],
),
),
),
],
)
),
),
],
),
),
),
);
}
}
导入“包装:颤振/材料.省道”;
类Home扩展了StatefulWidget{
@凌驾
状态createState(){
返回家园();
}
}
类HomeState扩展到State{
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
主体:容器(
子:堆栈(
儿童:[
容器(
装饰:盒子装饰(
梯度:线性梯度(
颜色:[
颜色,绿色,
蓝绿色,
]
)
),
),
填充物(
填充:仅限常量边集(顶部:65),
子:列(
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
宽度:100,
身高:100,
装饰:盒子装饰(
形状:BoxShape.circle,
边框:边框。全部(颜色:Colors.white60,宽度:2.0)
),
填充:边缘设置。全部(8),
孩子:圆环星(
背景颜色:Colors.white,
儿童:Icon(Icons.restaurant,尺寸:120,),
),
),
]
),
大小盒子(
身高:8,
),
正文(
“创世纪科技”,
样式:TextStyle(
fontWeight:fontWeight.bold,
尺寸:22,
颜色:颜色。白色
),
),
大小盒子(
身高:6,
),
正文(
“请采取以下预防措施”,
样式:TextStyle(
尺寸:16,
颜色:Colors.white70
),
),
],
),
),
容器(
页边距:仅限边缘集(顶部:350),
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:仅限borderRadius(
左上:半径。圆形(20),
右上角:半径。圆形(20),
)
),
),
容器(
页边距:仅限边缘集(顶部:250),
装饰:盒子装饰(
borderRadius:仅限borderRadius(
左上:半径。圆形(30),
右上角:半径。圆形(30)
)
),
孩子:填充(
填充:边缘集。全部(0),
子:GridView(
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
儿童:[
容器(
身高:200,
宽度:100,
孩子:卡片(
形状:圆形矩形边框(
边界半径:边界半径。圆形(15)
),
标高:10,
子:容器(
保证金:所有(4),
颜色:颜色,白色,
子:列(
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
Icon(Icons.restaurant,尺寸:120,),
正文(
“打喷嚏或咳嗽时捂住口鼻”,
样式:TextStyle(
fontWeight:fontWeight.bold
),
),
],
),
),
),
),
卡片(
形状:圆形矩形边框(
边界半径:边界半径。圆形(15)
),
标高:10,
子:容器(
保证金:所有(4),
颜色:颜色,白色,
子:列(
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
Icon(Icons.restaurant,尺寸:120,),
正文(
“避免用未洗手的手触摸你的脸”,
样式:TextStyle(
fontWeight:fontWeight.bold
),
),
],
),
),
),
卡片(
形状:圆形矩形边框(
边界半径:边界半径。圆形(15)
),
标高:10,
子:容器(
保证金:所有(4),
颜色:颜色,白色,
子:列(
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
Icon(Icons.restaurant,尺寸:120,),
正文(
“如果你愿意,就呆在家里
Container(
height: 200,
width: 100,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(Icons.restaurant, size: 120,),
Text(
"Some text here",
style: TextStyle(
fontWeight: FontWeight.bold
),
),
],
),
),
),
),
Scaffold(
body: Column(children: [
Flexible(
flex: 2,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Colors.green,
Colors.teal,
])),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(
flex: 1,
child: FractionallySizedBox(
heightFactor: 0.5,
child: Container(
width: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
border:
Border.all(color: Colors.white60, width: 2.0)),
padding: EdgeInsets.all(8),
child: CircleAvatar(
backgroundColor: Colors.white,
child: Icon(
Icons.restaurant,
),
),
),
),
),
SizedBox(
height: 8,
),
Text(
"Genesis Technologies",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
color: Colors.white),
),
SizedBox(
height: 6,
),
Text(
"Please take the following precautions",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16, color: Colors.white70),
),
],
),
),
),
Flexible(
flex: 3,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Colors.green,
Colors.teal,
])),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30))),
child: Padding(
padding: EdgeInsets.all(0),
child: GridView(
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2),
children: <Widget>[
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.restaurant,
size: 120,
),
Text(
"Cover your mouth and nose when yous sneeze or cough",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.restaurant,
size: 120,
),
Text(
"Avoid touching your face with unwashed hands",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.restaurant,
size: 120,
),
Text(
"Stay home if you don't need to get out for critical matters",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
),
],
)),
),
),
),
]),
);