小編給大家分享一下flutter中如何使用InkWell實(shí)現(xiàn)水波紋點(diǎn)擊效果,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

成都創(chuàng)新互聯(lián)是一家專業(yè)從事網(wǎng)站制作、網(wǎng)站設(shè)計(jì)的網(wǎng)絡(luò)公司。作為專業(yè)網(wǎng)站建設(shè)公司,成都創(chuàng)新互聯(lián)依托的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營(yíng)經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣及網(wǎng)站設(shè)計(jì)開(kāi)發(fā)服務(wù)!
在flutter 開(kāi)發(fā)中用InkWell或者GestureDetector將某個(gè)組件包起來(lái),已添加點(diǎn)擊事件。
GestureDetector 使用點(diǎn)擊無(wú)水波紋出現(xiàn),InkWell可以實(shí)現(xiàn)水波紋效果。正常情況下使用 :
InkWell( //單擊事件響應(yīng) onTap: () { }, child: Container( alignment: Alignment(0, 0), height: 28, width: 120, child: Text("InkWell單擊事件"), ), ),
如果在InkWell的上下都出現(xiàn)的顏色的設(shè)置,如上中的Container中如果加入了color:Colors.white,或者是Container中的其他widget設(shè)置了coloro屬性,這時(shí)候InkWell的水波紋效果會(huì)無(wú)效。
1 widget 設(shè)置水波紋點(diǎn)擊效果 并設(shè)置widget背景
new Center( child: new Material( // 設(shè)置背景顏色 默認(rèn)矩形 color: Colors.purple, child: new InkWell( //點(diǎn)擊事件回調(diào) onTap: () {}, //不要在這里設(shè)置背景色,for則會(huì)遮擋水波紋效果,如果設(shè)置的話盡量設(shè)置Material下面的color來(lái)實(shí)現(xiàn)背景色 child: new Container( width: 300.0, height: 50.0, //設(shè)置child 居中 alignment: Alignment(0, 0), child: Text("登錄",style: TextStyle(color: Colors.white,fontSize: 16.0),), ), ), ), ),
或者 可以使用 Ink來(lái)設(shè)置,與Material設(shè)置color 的區(qū)別是,Ink可設(shè)置背景的形狀樣式。
new Center( child: new Material( //INK可以實(shí)現(xiàn)裝飾容器,實(shí)現(xiàn)矩形 設(shè)置背景色 child: new Ink( //設(shè)置背景 默認(rèn)矩形 color: Colors.purple, child: new InkWell( //點(diǎn)擊事件回調(diào) onTap: () {}, child: new Container( width: 300.0, height: 50.0, //設(shè)置child 居中 alignment: Alignment(0, 0), child: Text("登錄",style: TextStyle(color: Colors.white,fontSize: 16.0),), ), ), ), ), ),
2 圓角widget 設(shè)置水波紋點(diǎn)擊效果
new Center( child: new Material(//INK可以實(shí)現(xiàn)裝飾容器 child: new Ink( //用ink圓角矩形 // color: Colors.red, decoration: new BoxDecoration( //不能同時(shí)”使用Ink的變量color屬性以及decoration屬性,兩個(gè)只能存在一個(gè) color: Colors.purple, //設(shè)置圓角 borderRadius: new BorderRadius.all(new Radius.circular(25.0)), ), child: new InkWell( //圓角設(shè)置,給水波紋也設(shè)置同樣的圓角 //如果這里不設(shè)置就會(huì)出現(xiàn)矩形的水波紋效果 borderRadius: new BorderRadius.circular(25.0), //設(shè)置點(diǎn)擊事件回調(diào) onTap: () { }, child: new Container( width: 300.0, height: 50.0, //設(shè)置child 居中 alignment: Alignment(0, 0), child: Text("登錄",style: TextStyle(color: Colors.white,fontSize: 16.0),), ), ), ), ), ),
如果 InkWell 與Ink 不同時(shí)設(shè)置相同的圓角,例如 lnk 設(shè)置的圓角為20,而Ink沒(méi)有設(shè)置,就會(huì)出現(xiàn) 矩形的水波紋點(diǎn)擊效果
3 圓角widget 設(shè)置自定義水波紋顏色點(diǎn)擊效果
new Center(child: new Material(child: new Ink( //設(shè)置背景 decoration: new BoxDecoration( color: Colors.purple, borderRadius: new BorderRadius.all(new Radius.circular(25.0)), ), child: new InkResponse( borderRadius: new BorderRadius.all(new Radius.circular(25.0)), //點(diǎn)擊或者toch控件高亮?xí)r顯示的控件在控件上層,水波紋下層 //highlightColor: Colors.yellowAccent, //點(diǎn)擊或者toch控件高亮的shape形狀 highlightShape: BoxShape.rectangle, //.InkResponse內(nèi)部的radius這個(gè)需要注意的是,我們需要半徑大于控件的寬,如果radius過(guò)小,顯示的水波紋就是一個(gè)很小的圓, //水波紋的半徑 radius: 300.0, //水波紋的顏色 splashColor: Colors.black, //true表示要剪裁水波紋響應(yīng)的界面 false不剪裁 如果控件是圓角不剪裁的話水波紋是矩形 containedInkWell: true, //點(diǎn)擊事件 onTap: () { print("click"); }, child: new Container( //不能在InkResponse的child容器內(nèi)部設(shè)置裝飾器顏色,否則會(huì)遮蓋住水波紋顏色的,containedInkWell設(shè)置為false就能看到是否是遮蓋了。 width: 300.0, height: 50.0, //設(shè)置child 居中 alignment: Alignment(0, 0), child: Text("登錄",style: TextStyle(color: Colors.white,fontSize: 16.0),), ), ), ), ), ),
4 圓角widget 設(shè)置高亮顏色點(diǎn)擊效果
new Center( child: new Material( child: new Ink( //設(shè)置背景 decoration: new BoxDecoration( color: Colors.purple, borderRadius: new BorderRadius.all(new Radius.circular(30.0)), ), child: new InkResponse( borderRadius: new BorderRadius.all(new Radius.circular(30.0)), //點(diǎn)擊或者toch控件高亮?xí)r顯示的控件在控件上層,水波紋下層 highlightColor: Colors.purple[800], //點(diǎn)擊或者toch控件高亮的shape形狀 highlightShape: BoxShape.rectangle, //.InkResponse內(nèi)部的radius這個(gè)需要注意的是,我們需要半徑大于控件的寬,如果radius過(guò)小,顯示的水波紋就是一個(gè)很小的圓, //水波紋的半徑 radius: 0.0, //水波紋的顏色 設(shè)置了highlightColor屬性后 splashColor將不起效果 splashColor: Colors.red, //true表示要剪裁水波紋響應(yīng)的界面 false不剪裁 如果控件是圓角不剪裁的話水波紋是矩形 containedInkWell: true, onTap: () { print( 'click'); }, child: new Container( //不能在InkResponse的child容器內(nèi)部設(shè)置裝飾器顏色,否則會(huì)遮蓋住水波紋顏色的,containedInkWell設(shè)置為false就能看到是否是遮蓋了。 width: 300.0, height: 50.0, //設(shè)置child 居中 alignment: Alignment(0, 0), child: Text("登錄",style: TextStyle(color: Colors.white,fontSize: 16.0),), ), ), ), ), ),
以上是“flutter中如何使用InkWell實(shí)現(xiàn)水波紋點(diǎn)擊效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
文章題目:flutter中如何使用InkWell實(shí)現(xiàn)水波紋點(diǎn)擊效果
本文URL:http://www.chinadenli.net/article28/gpcocp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、域名注冊(cè)、網(wǎng)站改版、服務(wù)器托管、全網(wǎng)營(yíng)銷(xiāo)推廣、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)