skip to Main Content

I’ve problem that says badge isn’t a function and can’t read it. And the second issue says, "The name ‘Badge’ is defined in the libraries". can u help me guys?

Widget _buildIconNotified() {
    return Badge(
      badgeColor: AppColor.actionColor,
      padding: EdgeInsets.all(3),
      position: BadgePosition.topEnd(top: -7, end: 0),
      badgeContent: Text('', style: TextStyle(color: Colors.white),
      ),
      child: _buildIcon(),
    );
  }

i’ve tried to remove badges dependency from pubspec.lock. but nothing changed

2

Answers


  1. I think the Badge widget is defined in more than one library. Material Library has a Badge widget and maybe you are also using some external pub package.

    Login or Signup to reply.
  2. If you check the documentation of the package at https://pub.dev/packages/badges it says:

    Attention! In Flutter 3.7 the Badge widget was introduced in the
    Material library, so to escape the ambiguous imports you need to
    import the package like this:

    import 'package:badges/badges.dart' as badges;
    

    And then use it as badges.Batch, like this for example

    badges.Badge(
      badgeContent: Text('3'),
      child: Icon(Icons.settings),
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search