当前位置: 首页> 科技> 数码 > Flutter——最详细(Badge)使用教程

Flutter——最详细(Badge)使用教程

时间:2025/7/11 8:18:37来源:https://blog.csdn.net/u013290250/article/details/140160496 浏览次数:3次

背景

主要常用于组件叠加上圆点提示;
使用场景,消息数量提示,消息红点提示

属性作用
backgroundColor红点背景色
smallSize设置红点大小
isLabelVisible是否显示
offset设置红点位置
alignment设置红点位置
child设置底部组件

代码块

class BadgePage extends StatelessWidget {const BadgePage({Key? key}) : super(key: key);Widget build(BuildContext context) {return const Wrap(spacing: 20,children: [Badge(backgroundColor: Colors.redAccent,smallSize: 10,child: Icon(Icons.update,size: 36,color: Colors.blue,),),Badge(backgroundColor: Colors.redAccent,smallSize: 10,label: Text('99'),isLabelVisible: false,largeSize: 14,child: Icon(Icons.update,size: 36,color: Colors.blue,),),Badge(backgroundColor: Colors.redAccent,smallSize: 10,label: Text('99'),largeSize: 14,child: Icon(Icons.update,size: 36,color: Colors.blue,),),Badge(backgroundColor: Colors.red,label: const Text('99'),smallSize: 20,textStyle: const TextStyle(fontSize: 8, color: Colors.red),padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),largeSize: 14,offset:  Offset(-4, -4),alignment: Alignment.bottomRight,child: const Icon(Icons.message, size: 36, color: Colors.indigo),),],);}
}

效果图

在这里插入图片描述

关键字:Flutter——最详细(Badge)使用教程

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: