I am new to flutter so please go easy on me I am practicing grid view I stuck up on what functionality should be used to take the specific image from grid items to the new page so i write the description about that image. here is my code,
GridView.count(
crossAxisCount: 2,
children: images
.map((e) => Container(
child: Container(
margin: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(10)),
child: Container(
decoration: BoxDecoration(
color: Colors.grey[900],
borderRadius: BorderRadius.circular(10)),
margin: EdgeInsets.all(8),
padding: EdgeInsets.all(8),
child: GestureDetector(
onTap: () {
},
child: Image(
image: AssetImage(e),
fit: BoxFit.fill,
),
),
),
),
))
.toList(),
crossAxisSpacing: 8,
mainAxisSpacing: 8,
padding: EdgeInsets.all(8),
),
From the snippet shared I get that you want to use the image on the new page after clicking on the item in grid view.
so in the next page widget's constructor declare something like this
//for stateful
class YourWidgetName extends StatefulWidget{
final String imagePath;
YourWidgetName({this.imagePath});
@override
_YourWidgetName createState() => _YourWidgetName();
}
class _LoginState extends State<Login> {
@override
Widget build(BuildContext context) {
//you can access imagepath as **widget.imagePath** passed
return Scafold();
}
}
//for stateless
class YourWidgetName extends StatefulWidget{
final String imagePath;
YourWidgetName({this.imagePath});
@override
Widget build(BuildContext context) {
//you can access imagepath as **imagePath** passed
return Scafold();
}
}
and in onTap function go for:
onTap: () =>
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
YourWidgetName(
imagePath: e)
)
)