How can I use Gesture with Gridview?

Asked

Viewed 40 times

-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});
}
  • 1

    Take a look at these two links, they should suit you: Navigating between screens in Flutter; Navigation between screens (Named Routes).

  • thanks, but my goal is from an image in gridview go to the page

  • 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.

  • If it helps you, the structure of the item should be return GestureDetector > Container > Column, that is, you need to leave the GestureDetector first, so each grid item will be clickable.

1 answer

0

You can cover the Container, dps of the return with the Gesture Detector Widget. Q ai the whole container will become a kind of clickable object. And you add onTap and put a Navigator on it for the page you want to display

Browser other questions tagged

You are not signed in. Login or sign up in order to post.