我有一个imageUrlList,它可以onTap以全屏方式打开图像,但是当我向后按下图像列表时,它会在页面顶部转到第一张图像,然后我应该一直向下滚动。
class _PageOneState extends State<PageOne> with AutomaticKeepAliveClientMixin<PageOne> {
ScrollController scroller = ScrollController();
@override
bool get wantKeepAlive => true;
List<dynamic> imageUrlList;
getImageUrls() async {
var url = 'https://motivational.firebaseio.com/PNG.json';
await http.get(url).then((res) {
if (res.statusCode == 200) {
var resData = json.decode(res.body);
setState(() {
imageUrlList = resData['URL'];
});}
});
}
@override
void initState() {
super.initState();
getImageUrls();
}
@override
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
resizeToAvoidBottomPadding: false,
body:imageUrlList != null ?
StaggeredGridView.countBuilder(
key: UniqueKey(),
padding: const EdgeInsets.all(8.0),
crossAxisCount: 4,
itemCount: imageUrlList.length,
itemBuilder: (BuildContext context,int index) {
String imgPath =imageUrlList[index].toString();
return new Material(
elevation: 8.0,
borderRadius:
new BorderRadius.all(new Radius.circular(8.0)),
child: new InkWell(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) =>
new FullScreenImagePage(imgPath)));
},
child: new Hero(
tag: imgPath,
child: new FadeInImage(
// image: new NetworkImage(imgPath),
image: new CachedNetworkImageProvider(imgPath),
fit: BoxFit.cover,
placeholder: new AssetImage("assets/pbv.png"),
),
),
),
);
},
staggeredTileBuilder: (i) =>
new StaggeredTile.count(2, i.isEven ? 2 : 3),
mainAxisSpacing: 8.0,
crossAxisSpacing: 8.0,
)
: new Center(
child: new CircularProgressIndicator(),
),
);
}
}
即使我在全屏模式下打开它,也可以粘贴到该特定图像上。
答案 0 :(得分:0)
尝试一下。 Navigator.of(context).pushNamed('/ screen2');