如何在Flutter材料应用菜单按钮中添加徽章

问题描述 投票:0回答:1

我想在Flutter材料应用菜单按钮中添加一些新内容的指示器(如下图中的红点)。怎么做?

enter image description here

flutter material-design flutter-layout
1个回答
1
投票

你可以使用dart的badges库,它正在对IconButton小部件产生这种效果,它带有有用的参数,如badgeColorbadgeTextColor。您可以使用以下步骤将其添加到项目中:

在你的pubspec.yaml文件中添加:

 badges: ^0.0.6 //latest version as of the time of writing the answer

然后运行flutter packages get命令,之后可以使用以下行导入它:

  import 'package:badges/badges.dart';
© www.soinside.com 2019 - 2024. All rights reserved.