yako-dev/flutter_badges

Unable to set transparent badge

aideric opened this issue · 6 comments

Environment

Package version: 3.0.2
Platform: Any
Device information: Any

Description

Expected behavior:
Can show transparent badge
Current behavior:
White badge

Steps to reproduce

  1. Download the example app
  2. Change the _shoppingCartBadge to the following
  Widget _shoppingCartBadge() {
    return badges.Badge(
      position: badges.BadgePosition.topEnd(top: 0, end: 3),
      badgeAnimation: badges.BadgeAnimation.slide(
          // disappearanceFadeAnimationDuration: Duration(milliseconds: 200),
          // curve: Curves.easeInCubic,
          ),
      showBadge: _showCartBadge,
      badgeStyle: badges.BadgeStyle(
        badgeColor: Colors.transparent,
      ),
      badgeContent: Text(
        _cartBadgeAmount.toString(),
        style: TextStyle(color: Colors.black),
      ),
      child: IconButton(icon: Icon(Icons.shopping_cart), onPressed: () {}),
    );
  }
  1. build the app

Images

The upper right shopping cart
Simulator Screen Shot - iPhone 14 Pro Max - 2023-02-06 at 11 59 10

Fix

: Material(
shape: border,
elevation: widget.badgeStyle.elevation,

Material(
  shape: border,
  elevation: widget.badgeStyle.elevation,
  type: MaterialType.transparency,

Using the MaterialType.transparency can set the Material widget to transparent background

ff56k commented

I found that the new badge shapes, twitter and instagram allows transparency as per normal while square and circle do not.

Thanks, @aideric and @ff56k. The fix is in the master branch already and will be published soon.

Hello, this problem has been solved 5 weeks ago, can we have an update on when the next release is planned please as it is a regression ?
I just need the info to know if I must switch to make my own badges or if it coming soon

Hey @hbock-42, I just uploaded version 3.0.3 with fix for transparent badge

@yadaniyil Thx a lot, working perfectly

Hi, using type: MaterialType.transparency opaques the elevation: widget.badgeStyle.elevation which defaults to 2. Maybe BadgeStyle could support a new property like allowTransparency then:
type: widget.badgeStyle.allowTransparency ? MaterialType.transparency : MaterialType.canvas.