Reputation: 2443
I am using GridView. I would like to go next page when these grids are pressed.
I would like to know how to each grid has parameter which would be hidden in grids and sent these parameters for next page.
How can I implement it?
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
mainAxisSpacing: 8.0,
crossAxisSpacing: 8.0,
crossAxisCount: 2,
childAspectRatio: 2,
),
padding: const EdgeInsets.all(8.0),
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) => Scoresheet()
));
},
child: Container(
decoration: BoxDecoration(
color: Colors.red,
boxShadow: const [ BoxShadow(blurRadius: 2), ]
),
child: Column(
children: <Widget>[
Text('${snapshot.data[index].game_name}', style: TextStyle(color: Colors.white)),
Text('')//IF IT COULD BE HIDDEN.
],
),
),
);
},
);
Upvotes: 1
Views: 60
Reputation: 27207
How You can pass the data with Navigator:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailScreen(todo: todos[index]),
),
);
How you can receive data at new screen:
class DetailScreen extends StatelessWidget {
// Declare a field that holds the Todo.
final Todo todo;
// In the constructor, require a Todo.
DetailScreen({Key key, @required this.todo}) : super(key: key);
@override
Widget build(BuildContext context) {
// Use the Todo to create the UI.
return Scaffold(
appBar: AppBar(
title: Text(todo.title),
),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Text(todo.description),
),
);
}
}
For more details Click here
Upvotes: 2