網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
showModalBottomSheet常用屬性
在使用showModalBottomSheet這個(gè)控件時(shí),想要設(shè)置圓角,在內(nèi)容widget設(shè)置不管用,然后直接看這個(gè)控件的實(shí)現(xiàn)原理,一看有個(gè)shape屬性,感覺(jué)有戲!果然設(shè)置完畢后,成功了。
注意:一定不要設(shè)置builder中的背景顏色,否則會(huì)覆蓋導(dǎo)致不能顯示出圓角!
showModalBottomSheet
shape可以設(shè)置成自己想要的形狀!通常直接設(shè)置圓角即可
-
isScrollControlled
:是否時(shí)全屏還是半屏 -
isDismissible
:外部是否可以點(diǎn)擊,false不可以點(diǎn)擊,true可以點(diǎn)擊,點(diǎn)擊后消失 -
backgroundColor
: 通常可以設(shè)置白色和透明, -
barrierColor
:設(shè)置遮擋底部的半透明顏色,默認(rèn)是black54,可以設(shè)置成透明的; -
enableDrag
: 是否可以向下拖動(dòng)關(guān)閉,默認(rèn)是true打開(kāi)的;
以下代碼:
showModalBottomSheet( context: context, isScrollControlled:false, backgroundColor: Colors.white, shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10))), builder: (BuildContext context) { return Container( height:50,//對(duì)話框高度就是此高度 child: Center(child: Text("居中文字")), ); });
flutter常見(jiàn)控件及例子
貝塞爾曲線
class BottomClipper extends CustomClipper<Path>{//切割類繼承 ? @override ? Path getClip(Size size) {//必備屬性一 ? ? var path = Path(); ? ? path.lineTo(0, 0); ? ? path.lineTo(0, size.height-60); ? ? var frit = Offset(size.width/2,size.height); ? ? var frit2 = Offset(size.width,size.height-60); ? ? path.quadraticBezierTo(frit.dx, frit.dy, frit2.dx, frit2.dy);//二次貝塞爾曲線 ? ? path.lineTo(size.width, size.height-60); ? ? path.lineTo(size.width, 0); ? ? return path; ? } ? @override ? bool shouldReclip(CustomClipper<Path> oldClipper) {//必備屬性二 ? ? // TODO: implement shouldReclip ? ? return false; ? } }
調(diào)用方法
?ClipPath( ? ? ? ? ? ? ? ? ? ? ? clipper: BottomClipper(), ? ? ? ? ? ? ? ? ? ? ? child: Container(), )
底部彈窗
底部彈起 showModalBottomSheet( context: context, builder:(BuildContext context){ return TabMyApp();//返回的是一個(gè)容器 } ); // ps:這個(gè)控件由于是系統(tǒng)自帶空間,下面帶了一個(gè)白色背景容器,導(dǎo)致彈起容器不能設(shè)置圓角 // 解決思路,因?yàn)檫@個(gè)背景的大小取決于覆蓋于其上的容器大小,故,可以給他一個(gè)很小的容器,再用用stack控件把一個(gè)較大的 // 的控件懸浮其上,在設(shè)置懸浮其上的容器,這樣看不到下邊大概是 Stack( alignment: const FractionalOffset(0.5, 0.935),//相對(duì)坐標(biāo) children: <Widget>[ SizeBox( height:10 ), // 看的到的容器 設(shè)置圓角 Container( height:300 ... ) ] )
下拉框
DropdownButtonHideUnderline( child:new DropdownButton( hint: new Text(''),//第一次把hint展示位下拉菜單條目的第一個(gè)值(默認(rèn)值) //設(shè)置這個(gè)value之后,選中對(duì)應(yīng)位置的item, //再次呼出下拉菜單,會(huì)自動(dòng)定位item位置在當(dāng)前按鈕顯示的位置處 value: selectItemValue,//下拉菜單選擇完之后,呈現(xiàn)給用的值 items: generateItemList(),//下拉菜單item點(diǎn)擊之后的回調(diào) iconSize: 24.0, isDense: true, onChanged: (T){ setState(() { selectItemValue=T; }); } ), ), 回調(diào)函數(shù) var selectItemValue; var selectItemValue1; /*DropDownState(){ selectItemValue=getDropdownMenuItem()[0].value; }*/ List<DropdownMenuItem> generateItemList() { List<DropdownMenuItem> items = new List(); for(int i =0;i<100;i++){ DropdownMenuItem itemi = new DropdownMenuItem( value: i.toString(), child: new Text(i.toString()) ); items.add(itemi); } return items; }
展開(kāi)閉合控件
ExpansionTile const ExpansionTile({ Key key, this.leading, @required this.title,//開(kāi)關(guān)的名稱 this.backgroundColor,//展開(kāi)背景色 this.onExpansionChanged, this.children = const <Widget>[], this.trailing, this.initiallyExpanded = false,//默認(rèn)關(guān)閉 }) : assert(initiallyExpanded != null), super(key: key);
輸入框
Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisSize: MainAxisSize.min, children: <Widget>[ Container( constraints: BoxConstraints.tightFor( width: 200.0), child: TextField( autofocus: false, //maxLength: 8, textAlign: TextAlign.right,//右對(duì)齊 keyboardType: TextInputType.number,//數(shù)字鍵盤(pán) onChanged: (v) { setState(() { price = double.parse('$v'); }); //記錄金額 print("onChange: $v"); }, decoration: InputDecoration( border: InputBorder.none,//去掉輸入框的下滑線 hintText: "0.00", hintStyle: TextStyle( fontSize: 14.0) ), ), ), Text(' 元 ',style: TextStyle(color: Colors.black),), ], ), ], ),
彈出框加疊加(一個(gè)紅包的樣子)
showDialog<Null>(//調(diào)用方法 context: context, //BuildContext對(duì)象 barrierDismissible: false, builder: (BuildContext context) { return new LoadingDialog( //調(diào)用對(duì)話框 text: '滾燙', ponto: "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=3463668003,3398677327&fm=58" ); }); //彈出的內(nèi)容 class LoadingDialog extends Dialog { String text;//傳遞的名字 String ponto;//頭像地址 LoadingDialog({Key key, @required this.text,this.ponto}) : super(key: key); @override Widget build(BuildContext context) { var stack = new Stack(//創(chuàng)建折疊層 alignment: const FractionalOffset(0.5, 0.935),//相對(duì)坐標(biāo) children: <Widget>[ //底層 new Material( //創(chuàng)建透明層 type: MaterialType.transparency, //透明類型 child: new Center( //保證控件居中效果 child: new SizedBox( width: 260.0, height: 420.0, child: new Container( decoration: ShapeDecoration( color: Colors.red, shape: RoundedRectangleBorder( borderRadius: BorderRadius.all( Radius.circular(8.0), ), ), ), child: new Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ //new CircularProgressIndicator(), ClipPath( clipper: BottomClipper(), child: Container( height: 360, width: 300, //color: decoration: ShapeDecoration( color: Colors.red[600], shape: RoundedRectangleBorder( borderRadius: BorderRadius.all( Radius.circular(8.0), ), ), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Image.network( ponto, scale: 3.0, ), SizedBox( height: 10, ), Text(text,style: new TextStyle(fontSize: 16.0,color: Colors.orangeAccent)), Text('恭喜發(fā)財(cái),大吉大利',style: new TextStyle(fontSize: 24.0,color: Colors.orangeAccent)), SizedBox( height: 100, ), ], ), ), ), ], ), ), ), ), ), //折疊層 Container( height: 200, child:Column( children: <Widget>[ Container( height: 70, width: 70, child: FlatButton( onPressed: (){ Navigator.push( context, new MaterialPageRoute(builder: (context) { return Hongbaoxiangqing(); })).then((String){//回調(diào)函數(shù) Navigator.pop(context); }); }, child: Text('開(kāi)',style: TextStyle(fontSize: 30),), ), decoration: BoxDecoration( //背景裝飾 color: Colors.amber[200], borderRadius: BorderRadius.circular(35), ), ), SizedBox( height: 70, ), FlatButton( onPressed: (){ Navigator.pop(context); }, child:Icon( Icons.clear,color: Colors.red[800], ) ) ], ), ), ], ); return stack; } } //美化界面 class BottomClipper extends CustomClipper<Path>{//切割類繼承 @override Path getClip(Size size) {//必備屬性一 var path = Path(); path.lineTo(0, 0); path.lineTo(0, size.height-60); var frit = Offset(size.width/2,size.height); var frit2 = Offset(size.width,size.height-60); path.quadraticBezierTo(frit.dx, frit.dy, frit2.dx, frit2.dy);//二次貝塞爾曲線 path.lineTo(size.width, size.height-60); path.lineTo(size.width, 0); return path; } @override bool shouldReclip(CustomClipper<Path> oldClipper) {//必備屬性二 // TODO: implement shouldReclip return false; } }
InkWell
- inkWell 在listTile里看到的控件,用這個(gè)可以自己組合Tile控件,并自帶點(diǎn)擊 和 長(zhǎng)按 兩個(gè)事件,
- 同時(shí)在用到按鈕的時(shí)候,我發(fā)現(xiàn)自帶的按鈕都有一定的大小,用InkWell寫(xiě)的按鈕可以自定義大小
多文字一行顯示不同效果
RichText( text: TextSpan( children: <TextSpan>[ TextSpan( text:' 黑名單功能目標(biāo):一是期望能打擊具有不良行為的個(gè)人和單位的社會(huì)聲譽(yù),促使其與您',style:TextStyle(fontSize: 15,color: Colors.white),), TextSpan(text:'和解',style:TextStyle(fontSize: 18,color: Colors.blue),), TextSpan(text:';二是為用戶提供一個(gè)向親朋好友',style:TextStyle(fontSize: 15,color: Colors.white),), TextSpan(text:'示警',style:TextStyle(fontSize: 18,color: Colors.red),), TextSpan(text:'的平臺(tái);三是心中有氣,',style:TextStyle(fontSize: 15,color: Colors.white),), TextSpan(text:'不吐不快',style:TextStyle(fontSize: 18,color: Colors.green),), TextSpan(text:'。',style:TextStyle(fontSize: 15,color: Colors.white),), ] ), ),
RichText為必須,TextSpan相當(dāng)于html里的span,屬于行級(jí)元素
原文鏈接:https://blog.csdn.net/u014627313/article/details/104760169
相關(guān)推薦
- 2022-07-15 go學(xué)習(xí)筆記讀取consul配置文件詳解_Golang
- 2023-01-19 Android?各版本兼容性適配詳解_Android
- 2022-02-25 antvg2中的Slider 滑塊插件的簡(jiǎn)介
- 2022-07-08 從生成CRD到編寫(xiě)自定義控制器教程示例_Golang
- 2022-11-11 Android利用Canvas類繪制圖形_Android
- 2022-12-13 Redis?Hash序列化存儲(chǔ)的問(wèn)題及解決方案_Redis
- 2023-01-01 echarts-xAxis-底部文字傾斜
- 2022-10-04 淺析C++模板類型中的原樣轉(zhuǎn)發(fā)和可變參數(shù)的實(shí)現(xiàn)_C 語(yǔ)言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支