class MyWidgetState extends State<MyWidget> {
@override
void initState() {
// adjust the provider based on the image type
precacheImage(new AssetImage('...'));
super.initState();
}
}
// you need to add transparent_image to your pubspec and import it
// as it is required to have the actual image fade in from nothing
import 'package:transparent_image/transparent_image.dart';
import 'package:flutter/material.dart';
...
FadeInImage(
placeholder: MemoryImage(kTransparentImage),
image: AssetImage('image.png'),
)
2 回答
在构建抽屉之前,使用precacheImage功能开始加载图像 . 例如,在包含抽屉的小部件中:
要摆脱"blink",您可以简单地将FadeInImage class与transparent_image结合使用,这将会褪色而不是立即出现 . 在您的情况下,用法如下所示: