You can resolve
to get an ImageStream
and addListener
to the ImageStream
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
State createState() => new MyAppState();
}
class MyAppState extends State<MyApp> {
Image _image = new Image.network(
'https://flutter.io/images/flutter-mark-square-100.png',
);
bool _loading = true;
@override
void initState() {
_image.image.resolve(new ImageConfiguration()).addListener((_, __) {
if (mounted) {
setState(() {
_loading = false;
});
}
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new Center(
child: _loading ? new Text('Loading...') : _image,
),
),
);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…