我正在尝试减少抖动获取图像的时间,以提高应用程序性能。
我尝试使用带有static const Image/AssetImage xyz = ...
的类将Image&AssetImage存储在单个文件中,以方便参考。
一些文章建议使用“继承的小部件”来执行此操作,但它们仅对字符串进行操作。我当前正在使用InheritedWidget:
class CommonImages extends InheritedWidget {
static CommonImages of(BuildContext context) =>
context.inheritFromWidgetOfExactType(CommonImages);
const CommonImages({Widget child, Key key}) : super(key: key, child: child);
static const Image get profilePic1 => Image(
fit: BoxFit.contain,
image: profilePicAsset,
);
static const AssetImage profilePicAsset =
AssetImage