0

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'),


          ),
        ],
      ),
    ), 
Anand
  • 4,355
  • 2
  • 35
  • 45

3 Answers3

0
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");
      },

          ),
        ],
      ),
    ), 
MohitJadav86
  • 782
  • 3
  • 11
0

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'),
      ),
Anand
  • 4,355
  • 2
  • 35
  • 45
0

You can navigate to the other page of Application by usign onTap() method of drawer widget

drawer: Drawer(
    child: ListView(
      // Important: Remove any padding from the ListView.
      padding: EdgeInsets.zero,
      children: <Widget>[
        UserAccountsDrawerHeader(
          accountName: Text("Alina Afzaal"),
          accountEmail: Text("alinaafzaalhussain@gmail.com"),
          currentAccountPicture: CircleAvatar(
            backgroundColor: Colors.white70,
            child: Text(
              "A",
              style: TextStyle(fontSize: 40.0, color: primaryColor),
            ),
          ),
        ),



        ListTile(
          leading: Icon(Icons.home), title: Text("Contact Me"),
          onTap: () {
            Navigator.push(
                context,
                MaterialPageRoute(
                builder: (BuildContext context) => Contact()));
          },
        ),



      ],
    ),
  ),