我有一个NetworkImage,我想知道何时完成加载。我怎么做?
您可以resolve获取ImageStream并addListener前往ImageStream
resolve
ImageStream
addListener
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, ), ), ); } }