错误: type 'Null' is not a subtype of type 'List
解决方案:使用异步方法,延迟刷新页面
解决效果图:
关键代码:
body: RefreshIndicator(
child: Image.network(
"http://www.devio.org/img/avatar.png",
width: 50,
height: 50,
),
//_asyncRefresh用于实现屏幕下拉时的回调函数
onRefresh: _asyncRefresh),
Future _asyncRefresh() async {
await Future.delayed(Duration(milliseconds: 200));
return null;
}
完整代码:
class _ImageWedgetInsState extends State{ @override Widget build(BuildContext context) { int _currentIndex = 0; return MaterialApp( title: "网络加载图片demo", theme: ThemeData(primarySwatch: Colors.green), home: Scaffold( appBar: AppBar( title: Text("加载网络图片demo"), leading: GestureDetector( onTap: () { Navigator.pop(context); }, child: Icon(Icons.arrow_back), ), ), //RefreshIndicator下拉刷新组件,想要获得下拉刷新效果必须配合列表ListView使用 body: RefreshIndicator( child: Image.network( "http://www.devio.org/img/avatar.png", width: 50, height: 50, ), //_asyncRefresh用于实现延迟刷新页面的回调函数 onRefresh: _asyncRefresh), ), ); } Future _asyncRefresh() async { await Future.delayed(Duration(milliseconds: 200)); return null; } }



