Home > Software design >  can someone help me regarding onTap fuction implementation in flutter i am beginner
can someone help me regarding onTap fuction implementation in flutter i am beginner

Time:08-26

can someone help me I want to create basic drawer navigation and implement the onTap function on item click

DrawerHeader(
            decoration: BoxDecoration(
              color: Colors.blue,
            ),
            child: Text('this is drawer header'),
          ),

          // creating ListTile for item 1 view
          ListTile(
            title: Text('Item 1'),
            onTap: null,
          ),

          // creating ListTile for item 2 view
          ListTile(
            title: Text('Item 2'),


          ),
        ],
      ),
    ), 

CodePudding user response:

onTap: () {
         print("Clicked");
      },

this is onTap event in ListTile

with your code this type it's work

 DrawerHeader(
            decoration: BoxDecoration(
              color: Colors.blue,
            ),
            child: Text('this is drawer header'),
          ),

          // creating ListTile for item 1 view
          ListTile(
            title: Text('Item 1'),
            onTap: null,
          ),

          // creating ListTile for item 2 view
          ListTile(
            title: Text('Item 2'),
        onTap: () {
       print("Clicked");
      },

          ),
        ],
      ),
    ), 

CodePudding user response:

Way 1

  ListTile(
        title: Text('Item 1'),
        onTap: () {
           print("Clicked");
        },
      ),

Way 2

 InkWell(
        onTap: () {
             print("Clicked");
           },
        child: ListTile(
        title: Text('Item 1'),
      ),
   

Way 3

 ListTile(
        title: InkWell(
        onTap: () {
              print("Clicked");
            },
        child: Text('Item 1'),
      ),
  • Related