flutter_badges icon indicating copy to clipboard operation
flutter_badges copied to clipboard

changing badge position makes it unclickable if using inkWell in badge content or gesture detector

Open moda20 opened this issue 4 years ago • 7 comments

i am trying to make a clickable badge and I noticed that changing the position using badgePosition.topEnd for example would make the badge unclickable as if the badge is in a place and the gesture detector i have in the badge content, is in another place. in the following example I am using an Inkwell but the same can be said for the gesture detector. this on top fo the fact that clicking the badge itself even in normal position wouldn't trigger unless u click on the center of it.

 Badge(
                                        child: Padding(
                                          padding: const EdgeInsets.only(bottom: 8),
                                          child: Text(
                                            "text"
                                          ),
                                        ),
                                        position: BadgePosition.topEnd(top: -15, end: -30),
                                        borderRadius: BorderRadius.all(Radius.circular(10)),
                                        shape: BadgeShape.circle,
                                        badgeColor: Colors.transparent,
                                        elevation: 0,
                                        badgeContent: Container(
                                          height: 25,
                                          width: 25,
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.all(Radius.circular(25)),
                                            color: Colors.transparent,
                                          ),
                                          child: Material(
                                            color: Colors.transparent,
                                            child:InkWell(
                                              child:  Icon(Icons.edit, color: MyTheme.grey300, size: 15,),
                                              onTap: (){
                                                print("sdsdsd")
                                              },
                                            ),
                                          ),
                                        ),
                                      ),

the sdsdsd log will not print when I am clearly tapping on the badge, even tapping around the badge won't make it print. is this a bug and is there a workaround for it ?

moda20 avatar Dec 27 '20 22:12 moda20

Stuck here too

Marcosmaliki avatar Mar 24 '21 13:03 Marcosmaliki

Any solution?

RajanEquitysoft avatar Aug 14 '21 09:08 RajanEquitysoft

Badges are not intended for click/tap interactions, it's about informing. If you want a clickable badge - simply create a custom button with rounded corners and update it's value if needed.

hexlogic avatar Sep 15 '21 21:09 hexlogic

Checking the source code, the badge is wrapped in IgnorePointer widget. Try setting it to false; ignorePointer: false,

Marcosmaliki avatar Sep 17 '21 05:09 Marcosmaliki

set ignorePointer: false will fix this issue,

InkWell(
   onTap: () {},
   child: Badge(
      ignorePointer: false,
      badgeContent: Text('3'),
      child: Icon(Icons.settings),
    )
)

walidashik avatar Sep 27 '21 05:09 walidashik

I can provide another not workling MWE, even with ignorePointer: false:

Card(
  child: GestureDetector(
    onTap: () {
      print("OnTap");
    },
    child: Badge(
      ignorePointer: false,
      badgeContent: SizedBox(height: 12, width: 12),
      child: Center(
        child: Text(""),
      ),
    ),
  ),
)

Only the area marked with the rectangle is clickable (e.g, the area on the Card):

grafik

Everything outside of the rectangular is not clickable.

boldt avatar Nov 23 '21 15:11 boldt

I have the same issue

Veeksi avatar Dec 04 '21 09:12 Veeksi

Hey everyone. The proper onTap parameter for the badge, where the whole badge widget is clickable will be introduced in Badges 3.0.0 with a lot of other features within a week. Closing the issue for now.

yadaniyil avatar Nov 29 '22 22:11 yadaniyil

Any update on 3.0.0?

boldt avatar Jan 10 '23 17:01 boldt

@boldt please try the new beta version https://pub.dev/packages/badges/versions/3.0.0-beta.1

yadaniyil avatar Jan 11 '23 10:01 yadaniyil