我在代码中添加了Dismissible小部件,以从JSON API中消除当前帖子图像,以通过在垂直方向上向上滑动(类似于火种轻扫)在关闭后显示下一个帖子图像。我已经尝试了onDismissed:(direction){}中的一些功能,但是不起作用。以下是我页面中包含的代码段:
class Swipe extends StatefulWidget {
@override
_SwipeState createState() => _SwipeState();
}
class _SwipeState extends State<Swipe> {
var user;
var image_url = 'http://example.com/upload/';
void getData() async {
var data = await getJson();
setState(() {
user = data['posts'];
});
}
@override
Widget build(BuildContext context) {
getData();
return new Scaffold(
appBar: new AppBar(
title: Text('News'),
backgroundColor: Colors.indigoAccent,
),
body: ListView.builder(
itemCount: user == null ? 0 : user.length,
itemBuilder: (context, i) {
return new Padding(
padding: EdgeInsets.only(
left: 10.0, right: 10.0, top: 5.0, bottom: 5.0),
child: new Dismissible(
key: Key(user[i].toString()),
direction: DismissDirection.vertical,
onDismissed: (direction) {
setState(() {.....});
},
child: new Column(
children: <Widget>[
new Image.network(
image_url + user[i]['news_image'],
fit: BoxFit.contain,
),
),
],
),
));
}
)
);
}
}