Home > Mobile >  Flutter - How to use icon and url launcher?
Flutter - How to use icon and url launcher?

Time:01-02

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

CodePudding user response:

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();
}

)

CodePudding user response:

You can use IconButton:

           Center(
            child: IconButton(
    
              icon: Icon(Icons.facebook_outlined),
    
              onPressed: () {
    
                setState(() {
    
                 _isBluetoothOn = !_isBluetoothOn;
    
                });
    
              },
    
            ),
    
          ),

CodePudding user response:

InkWell provides onTap, you can wrap Icon with it and I prefer splash effect. Also, you can use IconButton as @Afridi Kaya commented.

Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
  InkWell(
    onTap: () {
      print("tapped InkWell");
      /// todo: your launch
    },
    customBorder: const CircleBorder(),
    child: const Icon(
      Icons.facebook_outlined,
      size: 80,
      color: Colors.black,
    ),
  ),
  IconButton(
    onPressed: () {
      /// todo: your launch
      print("tapped IconButton");
    },
    iconSize: 80,
    padding: EdgeInsets.zero,
    alignment: Alignment.center,
    icon: const Icon(
      Icons.facebook_outlined,
      color: Colors.black,
    ),
  )
  • Related