A flutter package for creating badges.

Overview

Badges for Flutter

Pub Version

Installing:

In your pubspec.yaml

dependencies:
  badges: ^2.0.2
import 'package:badges/badges.dart';


Basic Usage:

    Badge(
      badgeContent: Text('3'),
      child: Icon(Icons.settings),
    )


Animations:

BadgeAnimationType.slide BadgeAnimationType.scale BadgeAnimationType.fade

Chips:

Sometimes you may want to use chip but it's too big, even if set padding to zero. This is where Badge comes handy.

    Chip(
      padding: EdgeInsets.all(0),
      backgroundColor: Colors.deepPurple,
      label: Text('BADGE', style: TextStyle(color: Colors.white)),
    ),
    Badge(
      toAnimate: false,
      shape: BadgeShape.square,
      badgeColor: Colors.deepPurple,
      borderRadius: BorderRadius.circular(8),
      badgeContent: Text('BADGE', style: TextStyle(color: Colors.white)),
    ),

Custom Usage

There are several options that allow for more control:

Properties Description
Widget badgeContent The content of badge. Usually Text or Icon.
Color badgeColor Background color of the badge.
Widget child The main widget. By default it's below the red badge. Usually Icon, IconButton, Text or button.
double elevation Shadow of the badge.
Gradient gradient Gradient color for the badge content.
bool toAnimate Whether animate badge when badge content changed or not.
BadgePosition position Can be one of BadgePosition.topStart(), BadgePosition.topEnd(), BadgePosition.bottomStart(), BadgePosition.bottomEnd(). Sometimes you want to create unique badge position or create new one manually. For this use BadgePosition.topEnd(top: -12, end: -20) or BadgePosition(start, top, end, bottom).
BadgeShape shape BadgeShape.circle or BadgeShape.square. You can use borderRadius to change border radius of badge of you use square BadgeShape.square.
BorderRadiusGeometry borderRadius Border radius of badge. Applies only if BadgeShape.square is used.
EdgeInsetsGeometry padding The padding of badge content.
Duration animationDuration The duration of badge animation when badge content is changed.
BadgeAnimationType animationType Can be one of BadgeAnimationType.slide, BadgeAnimationType.scale or BadgeAnimationType.fade.
bool showBadge Hide or show badge with animation using bool flag.
AlignmentGeometry alignment Alignment of the whole widget
bool ignorePointer Enable or disable (default) ignore pointer option
BorderSide borderSide Adds a border to the badge


License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details

Comments
  • No named parameter with the name 'overflow'.

    No named parameter with the name 'overflow'.

    After upgrading to 1.22.0-10.0.pre.196 in master channel error:

    Launching lib\main.dart on sdk gphone x86 in debug mode...
    /C:/Frameworks/flutter/.pub-cache/hosted/pub.dartlang.org/badges-1.1.1/lib/src/badge.dart:83:9: Error: No named parameter with the name 'overflow'.
            overflow: Overflow.visible,
            ^^^^^^^^
    /C:/Frameworks/flutter/packages/flutter/lib/src/widgets/basic.dart:3273:3: Context: Found this candidate, but the arguments don't match.
      Stack({
      ^^^^^
    

    Flutter doctor:

    flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel master, 1.22.0-10.0.pre.196, on Microsoft Windows [Version 10.0.19041.508], locale ru-RU)
    [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    [√] Android Studio (version 3.5)
    [√] VS Code (version 1.49.0)
    [√] Connected device (1 available)
    
    • No issues found!
    

    In pubspec.yaml:

    badges: ^1.1.1
    

    Looks like overflow was removed from Stack widget. image

    opened by worldofsites 10
  • changing badge position makes it unclickable if using inkWell in badge content or gesture detector

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

    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 ?

    opened by moda20 8
  • not working with flutter 1.19

    not working with flutter 1.19

    ../../../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/badges-1.1.1/lib/src/badge.dart:83:19: Error: The getter 'Overflow' isn't defined for the class 'BadgeState'.
     - 'BadgeState' is from 'package:badges/src/badge.dart' ('../../../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/badges-1.1.1/lib/src/badge.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'Overflow'.
            overflow: Overflow.visible,
                      ^^^^^^^^
    

    doctor

    Flutter 1.19.0-2.0.pre.213 • channel master • https://github.com/flutter/flutter.git
    Framework • revision eb1a6efe16 (9 hours ago) • 2020-05-30 21:58:02 -0400
    Engine • revision 923687f0e7
    Tools • Dart 2.9.0 (build 2.9.0-11.0.dev 6489a0c68d)
    
    Running flutter doctor...
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel master, 1.19.0-2.0.pre.213, on Mac OS X 10.15.3 19D76, locale en-KR)
    [!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
        ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
    [✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 3.6)
    [✓] Android Studio (version 3.6)
    [✓] VS Code (version 1.45.1)
    [✓] Connected device (3 available)
    
    
    
    opened by softmarshmallow 8
  • feat: add loop of the animation badge

    feat: add loop of the animation badge

    Connection with issue(s)

    Resolve issue https://github.com/yako-dev/flutter_badges/issues/66

    Adds a loop of the animation badge

    https://user-images.githubusercontent.com/82770717/199070446-b7a3e74f-76c4-49a7-a9af-0abc47129c00.mov

    opened by sawel24 7
  • No named parameter with the name 'clipBehavior'

    No named parameter with the name 'clipBehavior'

    Good Night After upgrading to badges: ^1.1.3 I got this error what should i do ???

    Compiler message: /C:/flutter/.pub-cache/hosted/pub.dartlang.org/badges-1.1.3/lib/src/badge.dart:83:9: Error: No named parameter with the name 'clipBehavior'. clipBehavior: Clip.none, ^^^^^^^^^^^^ /C:/flutter/packages/flutter/lib/src/widgets/basic.dart:3210:3: Context: Found this candidate, but the arguments don't match. Stack({ ^^^^^

    opened by shw2ypro 6
  • Fix for deprecated overflow parameter on Stack widget

    Fix for deprecated overflow parameter on Stack widget

    Fix for "No named parameter with the name 'overflow'" error. Related to issue: https://github.com/yako-dev/flutter_badges/issues/27 Related to flutter core updates: https://github.com/flutter/flutter/commit/7948a7863bd8931e4e029c5b109f26c1b3dcf8ea

    opened by worldofsites 6
  • Button in badgeContent not work?

    Button in badgeContent not work?

    I have a widget (button) in param badgeContent. When i install the app for the first time, the button doesn't work but when i touch the 3rd time it works. Can anyone tell me what's wrong with it?

    bug 
    opened by nguyenquanghuy19 4
  • feat: add duration of the appearance Badge

    feat: add duration of the appearance Badge

    Connection with issue(s)

    Resolve issue https://github.com/yako-dev/flutter_badges/issues/67

    Adds new variable a duration of the appearance Badge

    Testing and Review Notes

    You need to create a Badge widget, set the appearanceDration, and check how long the Badge will animate before full appearance