Alex Ali
Alex Ali

Reputation: 1369

Flutter: How to put GestureDetector for items displayed from list

I have an app that displays a list of categories and I want to add GestureDetector for every category shown on the screen to activate the selected one.

My list is like so: List<list> category;

Here is my code:

ListView.builder(
            scrollDirection: Axis.horizontal,
            itemCount: category.length,
            itemBuilder: (context,index){
              bool isSelected = false;
              if (index == 0) {
                isSelected = true;
              }
              return Row(
                children: <Widget>[
                  Column(
                    children: <Widget>[
                      Container(
                        width: 68,
                        height: 68,
                        decoration: BoxDecoration(
                          color: isSelected?
                          Colors.white:
                          Colors.transparent,
                          borderRadius: BorderRadius.circular(16),
                          border: Border.all(
                            color: Colors.white,
                            width: 1,
                          ),
                          boxShadow: isSelected
                          ?[
                            BoxShadow(
                              color: Color(0x14000000),
                              blurRadius: 10
                            )
                          ]: null
                        ),
                        child: Center(
                          child: Image.asset(category[index].imageUrl),
                        ),
                      ),
                    ],
                  ),
                ],
              );
            },
          ),

Upvotes: 1

Views: 1026

Answers (1)

Jitesh Mohite
Jitesh Mohite

Reputation: 34170

Use GestureDetector on Row

GestureDetector(
    onTap: () {
     // Call back of click event
    },
    child: Row(
    
    ),
  ),

Upvotes: 2

Related Questions