Solved: Flutter - How to use icon and url launcher?

Question

Asked by Mateusz P on January 02, 2022 (source).

I'm learning flutter by my own and I would like to make an icon that works with url_launcher but I have no idea how to do it. When I'm using icon, onTap doesn't work. How can I solve this issue?

Row(
  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  children: const [
    Icon(
      Icons.facebook_outlined,
      size: 80,
      color: Colors.black,
    )
  ],
),

Answer

Question answered by saurabh (source).

You can use Gesturedecture or IconButton

  Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        GestureDetector(
         onTap:(){
          launchUrl();
        }
         child:Icon(
          Icons.facebook_outlined,
          size: 80,
          color: Colors.black,
        )
       )
      ],
    )

IconButton

IconButton(
icon: Icon(
      Icons.facebook_outlined,
      size: 80,
      color: Colors.black,
    ),
onPressed:(){
 launchUrl();
}

)

Video Answers on YouTube

DART FLUTTER
SHARE: