How can I click item in StaggeredGridView
in Flutter?
I want to add Navigator
and send link photo to another screen.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter Staggered View",
home: MyHome(),
);
}
}
class MyHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: StaggeredGridView.countBuilder(
crossAxisCount: 4,
itemCount: 15,
itemBuilder: (BuildContext context, int index) => new Container(
height: 120.0,
width: 120.0,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage('https://picsum.photos/500/500?random=$index') ,
fit: BoxFit.fill,
),
shape: BoxShape.rectangle,
),
),
staggeredTileBuilder: (int index) =>
new StaggeredTile.count(2, index.isEven ? 3 : 2),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
),
),
);
}
}
You can check the below code. You need to use GestureDetector. Then push it in another class. please check my answer for details.