Image 颤振:图像高度动态将根据文本高度的增加和减少而改变
在GridView生成器索引中,我在顶部设置了一个图像,在底部设置了多行文本。下一步,我想图像的高度大小将动态变化,而文本行将被改变。 假设,当底部文本行增加时,索引中的顶部图像高度将降低Image 颤振:图像高度动态将根据文本高度的增加和减少而改变,image,flutter,dart,text,gridview,Image,Flutter,Dart,Text,Gridview,在GridView生成器索引中,我在顶部设置了一个图像,在底部设置了多行文本。下一步,我想图像的高度大小将动态变化,而文本行将被改变。 假设,当底部文本行增加时,索引中的顶部图像高度将降低 class category_route extends StatelessWidget { @override Widget build(BuildContext context) { var sizeDevice = MediaQuery.of(context).size; final o
class category_route extends StatelessWidget {
@override
Widget build(BuildContext context) {
var sizeDevice = MediaQuery.of(context).size;
final orientation = MediaQuery.of(context).orientation;
final double itemHeight = (sizeDevice.height - kToolbarHeight - 24) / 3;
final double itemWidth = sizeDevice.width / 3;
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.yellow,
body: GridView.builder(
padding: EdgeInsets.all(8),
itemCount: categoryTitleArray.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: (orientation == Orientation.portrait) ? 3 : 4,
crossAxisSpacing: 5,
mainAxisSpacing: 5,
childAspectRatio: (itemWidth / itemHeight),
),
itemBuilder: (BuildContext context, int index) {
return new Card(
child: new GridTile(
child: Image.asset(categoryImageArray[index],
),
footer: Text("${categoryTitleArray[index]}"),
),
);
},
),
),
);
}
}
请使用此选项,而不是使用网格
return
new Card(
child: new Column(
children: [
Expanded(
child: Image.network(
categoryImageArray[index],
),
),
Text("${categoryTitleArray[index]}")
],
),
);
我对此进行了测试,效果非常好。希望我能回答这个问题