Flutter 徽章
用于创建徽章的 Flutter 包。
安装
在你的 pubspec.yaml 中
dependencies:
badges: ^1.0.0
import 'package:badges/badges.dart';
基本用法
Badge(
badgeContent: Text('3'),
child: Icon(Icons.settings),
)
动画
![]() |
![]() |
![]() |
|---|---|---|
BadgeAnimationType.slide |
BadgeAnimationType.scale |
BadgeAnimationType.fade |
自定义用法
有几个选项可以提供更多控制
| 属性 | 描述 |
|---|---|
Widget badgeContent |
徽章的内容。通常是Text或Icon。 |
Color badgeColor |
徽章的背景色。 |
Widget 子项 |
主小部件。默认情况下,它位于红色徽章下方。通常是Icon、IconButton、Text或按钮。 |
double elevation |
徽章的阴影。 |
bool toAnimate |
当徽章内容更改时是否要为徽章设置动画。 |
BadgePosition position |
可以是BadgePosition.topLeft()、BadgePosition.topRight()、BadgePosition.bottomLeft()、BadgePosition.bottomRight()之一。有时您想创建独特的徽章位置或手动创建新的位置。为此,请使用BadgePosition.topRight(top: -12, right: -20)或BadgePosition.(left, top, right, bottom)。 |
BadgeShape shape |
BadgeShape.circle或BadgeShape.square。如果您使用方形BadgeShape.square,则可以使用borderRadius来更改徽章的圆角。 |
double borderRadius |
徽章的圆角。仅当使用BadgeShape.square时适用。 |
EdgeInsets padding |
徽章内容的内边距。 |
Duration animationDuration |
徽章内容更改时徽章动画的持续时间。 |
BadgeAnimationType animationType |
可以是BadgeAnimationType.slide、BadgeAnimationType.scale或BadgeAnimationType.fade之一。 |


