-1
I need help when the user clicks on the image, open the corresponding page.
import 'package:flutter/material.dart';
import 'package:health/page-health/doador.dart';
import 'package:health/page-health/imc.dart';
class GridDasboard extends StatelessWidget {
Items item1= new Items( title: "IMC - Peso e Altura", img: "assets/images/balanca.png" );
Items item2 = new Items(title: "Doador ", img: "assets/images/doador.png");
var links = [
IMCPage(),
DOAPage(),
];
@override
Widget build(BuildContext context) {
List<Items> myList = [item1, item2];
var color = 0xffD3D3D3;
return Flexible(
child: GridView.count(
childAspectRatio: 1.0,
padding: EdgeInsets.only(left: 8, right: 8),
crossAxisCount: 2,
crossAxisSpacing: 18,
mainAxisSpacing: 18,
children: myList.map((data) {
return Container(
decoration: BoxDecoration(
color: Color(color), borderRadius: BorderRadius.circular(10)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset(
data.img,
width: 42,
),
SizedBox(
height: 14,
),
Text(
data.title,
style: Theme.of(context).textTheme.headline6,
),
GestureDetector(
onTap: () async {
await Items();
},
),
],
),
);
}).toList()),
);
}
}
class Items {
String title;
String img;
Items({this.title, this.img});
}
Take a look at these two links, they should suit you: Navigating between screens in Flutter; Navigation between screens (Named Routes).
– Matheus Ribeiro
thanks, but my goal is from an image in gridview go to the page
– Paula Alvim
Right... Then EDIT your question and explain your problem, in more detail. I saw that you are using the
GestureDetector
that leaves the Widget clickable, so just apply what was taught in the videos I indicated.– Matheus Ribeiro
If it helps you, the structure of the item should be
return GestureDetector > Container > Column
, that is, you need to leave theGestureDetector
first, so each grid item will be clickable.– Matheus Ribeiro