博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Flutter UI基础 - Widgets 之 InkWell 和 Ink
阅读量:4049 次
发布时间:2019-05-25

本文共 1502 字,大约阅读时间需要 5 分钟。

InkWell

InkWell组件在用户点击时出现“水波纹”效果,InkWell简单用法:

InkWell(    onTap: (){},    child: Text('这是InkWell点击效果'),)

onTap是点击事件回调,如果不设置无法出现“水波纹”效果,效果如下:

 

设置水波纹颜色: 

InkWell(    onTap: () {},    splashColor: Colors.red,    ...)

效果如下:

 

 

 

设置高亮颜色: 

InkWell(    onTap: () {},    highlightColor: Colors.blue,    ...)

高亮颜色是按住时显示的颜色,效果如下:

给字体添加边距和圆角边框,扩大“水波纹”效果:

InkWell(    onTap: (){},    child: Container(      padding: EdgeInsets.symmetric(horizontal: 20,vertical: 8),      decoration: BoxDecoration(        border:Border.all(color: Colors.blue),        borderRadius: BorderRadius.all(Radius.circular(30))                      ),      child: Text('这是InkWell点击效果'),    ),)

效果如下:

发现“水波纹”超出的了圆角边框,如何解决这个问题呢?Ink隆重登场。

Ink

Ink的官方解释:

A convenience widget for drawing images and other decorations on [Material] widgets, so that [InkWell] and [InkResponse] splashes will render over them.

简单翻译:Ink控件用于在[Material]控件上绘制图像和其他装饰,以便[InkWell]、[InkResponse]控件的“水波纹”效果在其上面显示。

上面的问题修改代码如下:

Ink(    decoration: BoxDecoration(       gradient: LinearGradient(       begin: Alignment.topLeft,       end: Alignment.bottomRight,       colors: [Color(0xFFDE2F21), Color(0xFFEC592F)]),       borderRadius: BorderRadius.all(Radius.circular(20))),    child: InkWell(      borderRadius: BorderRadius.all(Radius.circular(20)),      child: Container(        padding: EdgeInsets.symmetric(vertical: 8, horizontal: 20),        child: Text(          '这是InkWell的点击效果',          style: TextStyle(color: Colors.white),        ),    ),    onTap: () {},  ),)

效果如下:

 

 

 

 

 

转载地址:http://nonci.baihongyu.com/

你可能感兴趣的文章
mybatis mybatis plus mybatis jpa hibernate spring data jpa比较
查看>>
也许是世界上最简单最灵活的JAVA CRUD开发方法
查看>>
支付宝生活号服务号 用户信息获取 oauth2 登录对接 springboot java
查看>>
提交jar包到maven中央仓库2019最新版本
查看>>
eclipse servers view tomcat内存配置
查看>>
HandlerExceptionResolver 踩坑记录
查看>>
CodeForces #196(Div. 2) 337D Book of Evil (树形dp)
查看>>
uva 12260 - Free Goodies (dp,贪心 | 好题)
查看>>
uva-1427 Parade (单调队列优化dp)
查看>>
poj 1155 TELE (树形背包dp)
查看>>
【设计模式】学习笔记13:组合模式(Composite)
查看>>
hdu 1011 Starship Troopers (树形背包dp)
查看>>
hdu 1561 The more, The Better (树形背包dp)
查看>>
【设计模式】学习笔记14:状态模式(State)
查看>>
poj 1947 Rebuilding Roads (树形背包dp)
查看>>
【设计模式】学习笔记15:代理模式(Proxy Pattern)
查看>>
hdu 4003 Find Metal Mineral (树形背包dp)
查看>>
uva 1407 Caves (树形背包dp)
查看>>
poj 2486 Apple Tree (树形背包dp)
查看>>
poj 3345 Bribing FIPA (树形背包dp | 输入坑)
查看>>