安装
badges: ^3.1.1
引用
import 'package:badges/badges.dart' as badges;
基础使用
badges.Badge(
badgeContent: Text('3'), /*红点中的文本*/
child: Icon(Icons.settings), /*嵌套的 widget*/
)
高级配置
badges.Badge(
position: badges.BadgePosition.topEnd(top: -10, end: -12), /*定位的位置*/
showBadge: true, /*是否显示小红点*/
ignorePointer: false, /*是否忽略红点的点击事件*/
onTap: () {},/*点击事件*/
badgeContent:Icon(Icons.check, color: Colors.white, size: 10), /*红点的内容*/
badgeAnimation: badges.BadgeAnimation.rotation( /*动画效果*/
animationDuration: Duration(seconds: 1),
colorChangeAnimationDuration: Duration(seconds: 1),
loopAnimation: false,
curve: Curves.fastOutSlowIn,
colorChangeAnimationCurve: Curves.easeInCubic,
),
badgeStyle: badges.BadgeStyle( /*红点的样式*/
shape: badges.BadgeShape.square,
badgeColor: Colors.blue,
padding: EdgeInsets.all(5),
borderRadius: BorderRadius.circular(4),
borderSide: BorderSide(color: Colors.white, width: 2),
borderGradient: badges.BadgeGradient.linear(
colors: [Colors.red, Colors.black]),
badgeGradient: badges.BadgeGradient.linear(
colors: [Colors.blue, Colors.yellow],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
elevation: 0,
),
child: Text('Badge'), /*子组件 */
),