1 IconButton IconButton一个Material图标按钮,点击时会有水波动画 2 构造函数 IconButton({ Key key, this.iconSize =
视频演示地址: https://www.bilibili.com/video/BV1jomdBBE4H/ 目录 概述 特性 快速开始 API 参考 使用示例 主题配置 最佳实践 常见问题 总结 概述 IconButton 与文字按钮的主要区别在于: PrimaryButton/SecondaryButton/TextButton:显示文字(可带图标) IconButton:仅显示图标,无文字 设计理念 图标按钮采用极简设计 响应式设计 在小屏幕上考虑使用 smaller 尺寸 保持按钮之间的合理间距 确保触摸目标足够大(至少 32vp) 常见问题 Q1: IconButton 和其他按钮有什么区别? A: 主要区别在于显示内容: PrimaryButton/SecondaryButton/TextButton:显示文字(可带图标) IconButton:仅显示图标,无文字 IconButton 更适合工具栏 IconButton 非常适合用于工具栏场景: Row({ space: 8 }) { IconButton({ textIcon: 'B', // B = Bold(粗体) buttonSize
常用带事件处理的组件 FloatingActionButton RaisedButton IconButton ToggleButton Flutter 1.9 新推出的一个组件; IconButton IconButton( icon: Icon(Icons.description), onPressed: () {
通过 源码可以知道,本质上这个颜色属性是传入到 IconButton 组件构造方法中的。 IconButton 组件 IconButton 是一个具有圆形水波纹点击效果的组件,必须传入一个子组件 icon 和回调函数 onPressed 。 这不得不让图标按钮的占位区域扩大,当多个 IconButton 排列时,如下所示,默认情况下,水波纹区域太大,又会显得拥挤: 不过可以通过 splashRadius 来控制水波纹的扩散半径。 ---->[IconButton#build]---- if (theme.useMaterial3) { final Size? , ); } 从这里可以看出,通过 IconButton 组件封装构建逻辑,也有利于功能拓展。
this.bottomOpacity = 1.0, }) 3 常用属性 3.1 tleading:在标题前面显示的一个控件,在首页通常显示应用的 logo;在其他界面通常显示为返回按钮 leading: IconButton onPressed: () {}, ), 3.2 title:标题,通常显示为当前界面的标题文字,可以放组件 title: "AppBarWidget", 3.3 actions:通常使用 IconButton 来表示,可以放按钮组 actions: <Widget> IconButton( icon: Icon(Icons.search), onPressed: () {}, ), IconButton( icon: Icon(Icons.more_horiz), onPressed: () {}, ) , 3.4
Button; Flutter 中没有 Button Widget,但提供了很多不同类型的 Child Button Widget;和尚分析源码整体可分为 RawMaterialButton 和 IconButton ;最终 RawMaterialButton 和 IconButton 都是由 ConstrainedBox 填充绘制; ? IconButton 系列 IconButton 系列属于图标按钮,使用相对简单;其核心是 InkResponse 水波纹效果; IconButton 源码分析 const IconButton({ ;长按会由 tooltip 提醒,点击为默认主题色; IconButton(icon: Icon(Icons.android), tooltip: 'IconButton tootip1', onPressed ;其中 icon 颜色为 cyan,点击高亮背景色为 deepPurple,水波纹颜色为 redAccent;注意当 icon 自身设置颜色时 color 属性不生效; IconButton(icon:
我找不到任何显示如何创建IconButton类似于的圆的示例FloatingActionButton。 如果需要背景图像,则可以将CircleAvatar与IconButton一起使用。设置backgroundImage属性。 CircleAvatar( backgroundColor: Colors.blue, radius: 20, child: IconButton Colors.white, onPressed: () {}, ), ), 实际上,有一个示例如何创建类似于FloatingActionButton的圆形IconButton ShapeDecoration( color: Colors.lightBlue, shape: CircleBorder(), ), child: IconButton
通常使用IconButton来表示,可以放按钮组; 4. bottom 底部控件。通常用tabBar来表示放置Tab标签栏; 5. backgroundColor 导航背景颜色。 背景颜色 backgroundColor: Colors.red, // 前置控件 leading: IconButton // 后置控件 actions: <Widget>[ // 按钮1 IconButton { }, ), // 按钮2 IconButton
添加leading leading: new IconButton( icon: Icon(Icons.arrow_back), onPressed: () {}, ), 添加actions actions: <Widget>[ new IconButton onPressed: () { print("添加"); }, ), new IconButton NestedScrollView.sliverOverlapAbsorberHandleFor(context), child: SliverAppBar( leading: new IconButton forceElevated: innerBoxIsScrolled, actions: <Widget>[ new IconButton
this.title,//Toolbar 中主要内容,通常显示为当前界面的标题文字 this.actions,//一个 Widget 列表,代表 Toolbar 中所显示的菜单,对于常用的菜单,通常使用 IconButton Scaffold设置了Drawer则显示打开Drawer的图标 如果leading属性未设置,Scaffold也未设置Drawer,此时如果有前一个路由,则显示BackButton leading: IconButton Widget build(BuildContext context) { return Scaffold( appBar: AppBar( leading: IconButton false后将不会自动出现返回箭头 centerTitle: true, //如果想要文字居中的话 actions: <Widget>[ IconButton ( icon: Icon(Icons.menu), onPressed: () {}, ), IconButton
return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( leading: IconButton 大前端之旅'), backgroundColor: Colors.transparent, elevation: 0, actions: [IconButton return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( leading: IconButton backgroundColor: Colors.green.withOpacity(0.6), elevation: 0, actions: [ IconButton return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( leading: IconButton
this.title,//Toolbar 中主要内容,通常显示为当前界面的标题文字 this.actions,//一个 Widget 列表,代表 Toolbar 中所显示的菜单,对于常用的菜单,通常使用 IconButton Scaffold设置了Drawer则显示打开Drawer的图标 如果leading属性未设置,Scaffold也未设置Drawer,此时如果有前一个路由,则显示BackButton leading: IconButton Widget build(BuildContext context) { return Scaffold( appBar: AppBar( leading: IconButton false后将不会自动出现返回箭头 centerTitle: true, //如果想要文字居中的话 actions: <Widget>[ IconButton ( icon: Icon(Icons.menu), onPressed: () {}, ), IconButton
本文介绍Flutter中常用按钮控件,包括:MaterialButton 、RaisedButton 、FlatButton 、IconButton 、FloatingActionButton 、OutlineButton IconButton 图标按钮,只能是纯图标,按钮不可展示文案。 FloatingActionButton 浮动按钮,可显示文字和图标,二者选其一。 FlatButton( child: new Text('FlatButton'), onPressed: () {}, ), 3.4、IconButton new IconButton( icon: new Icon(Icons.wifi), tooltip: 'click IconButton',
page.add( ft.Text("计数器", size=20), count, ft.Row( [ ft.IconButton (ft.icons.ADD, on_click=add_click), ft.IconButton(ft.icons.REMOVE, on_click=subtract_click 加减按钮(IconButton):这两个按钮是IconButton组件,ft.icons.ADD和ft.icons.REMOVE是按钮上的图标。 (ft.icons.ADD, on_click=add_click), ft.IconButton(ft.icons.REMOVE, on_click=subtract_click , size=20), count, ft.Row( [ ft.IconButton
item.quantity}", modifier = Modifier.padding(8.dp)) Row(modifier = Modifier.padding(8.dp)) { IconButton Icon(imageVector = Icons.Default.Edit, contentDescription = null) } IconButton Icons.Default.Delete, contentDescription = null) } } }}2.2.1 解释代码ListItem 组件展示了列表项的详细信息, IconButton = Modifier.padding(8.dp)) Row( modifier = Modifier .padding(8.dp)) { IconButton Icon(imageVector = Icons.Default.Edit, contentDescription = null) } IconButton
Icons.adb, Icons.airplanemode_active, Icons.account_box_rounded, ]; 然后通过每个图标对应的IconData来构建一个IconButton icon) { return Padding( padding: const EdgeInsets.symmetric(vertical: 10.0), child: IconButton buttonAnimation.reverse() : buttonAnimation.forward(); }, ) ); } 这里我们使用的是IconButton ,为了在不同IconButton之间留一些空间,我们将IconButton封装在Padding中。
Widget build(BuildContext context) { return Scaffold( appBar: AppBar( leading: new IconButton '), centerTitle: true, elevation: 0.0, actions: <Widget>[ IconButton Widget build(BuildContext context) { return Scaffold( appBar: AppBar( leading: new IconButton '), centerTitle: true, elevation: 0.0, actions: <Widget>[ IconButton
这适用于`IconButton`,`InkWell`,`ListTile`和许多其他部件。 Colors.transparent, hoverColor: Colors.transparent, ) child: child, ) 您还可以直接为特定小部件禁用此功能: IconButton
在Flutter中,有很多的按钮组件,常见的有:FlatButton、RaisedButton、OutlineButton、IconButton、ButtonBar、FloatingActionButton IconButton、ButtonBar、自定义按钮组件 IconButton这个组件一般是用在定义顶部导航栏上的按钮: appBar: AppBar( centerTitle : true, title: Text("用户中心"), //定义顶部导航栏的左侧按钮 leading: IconButton( icon onPressed: () => print("menu"), ), //定义顶部导航栏的右侧按钮组 actions: <Widget>[ IconButton 好,到现在为止,我们了解了RaisedButton、FlatButton、OutlineButton、IconButton和ButtonBar,还有一个FloatingActionButton我们会在下面单独开一个小节去讲
Icons.adb, Icons.airplanemode_active, Icons.account_box_rounded, ];然后通过每个图标对应的IconData来构建一个IconButton IconData icon) { return Padding( padding: const EdgeInsets.symmetric(vertical: 10.0), child: IconButton buttonAnimation.reverse() : buttonAnimation.forward(); }, ) ); }这里我们使用的是IconButton ,为了在不同IconButton之间留一些空间,我们将IconButton封装在Padding中。