我正在使用 device_apps.dart 制作一个具有大应用程序图标的应用程序启动器。当我尝试创建大图标时,应用程序会缩放到不同的大小。
我可以使用每个图标图像的缩放或宽度属性更改图标的宽度,但由于某种原因,图标的缩放比例不同。如果我把图标稍微大一点,没有问题,但是把它们变成我想要的大小会导致应用程序大小不同。有谁知道造成这种情况的原因以及解决方案是什么?
return GridView.count(
crossAxisCount: columns,
//crossAxisSpacing: 0,
//mainAxisSpacing: 0,
children: List.generate(allApps.length, (index) {
return GestureDetector(
onTap:() {
DeviceApps.openApp(allApps[index].packageName);
},
child: Column(
children: [
Image.memory(
(allApps[index] as ApplicationWithIcon).icon,
//width: 150,
scale: .5,
),
Text(
"${allApps[index].appName}",
style: TextStyle(
color: Colors.white,
fontSize: 38,
),
overflow: TextOverflow.ellipsis,
)
]
),
);
})
);
}
如果你想制作相同的尺寸,你可以用特定尺寸包裹你的图像并在图像上设置
fit
属性
Column(
children:[
SizedBox(
// you can set only one or both
// width:
height: 200
child:Image.memory((allApps[index] as ApplicationWithIcon).icon,
// Use this to scale down or scale up to fit the frame
fit: BoxFit.contain
),
在这里查看另一个选项
BoxFit
:
https://api.flutter.dev/flutter/painting/BoxFit.html