IconTextButton
IconTextButton
是一個圖文按鈕,F(xiàn)lutter的RaisedButton按鈕RaisedButton.icon()按鈕只能實(shí)現(xiàn)左圖右文字
IconTextButton.icon()
可以實(shí)現(xiàn)四種樣式:
圖在上文字在下彭则,圖在下文字在上哎媚,圖在左文字在右,圖在右文字在左
使用也很簡單,其它屬性設(shè)置和RaisedButton.icon()
一樣阶女,
只需要設(shè)置屬性iconTextAlignment
颊糜,它是一個枚舉值 :
enum IconTextAlignment {
iconTopTextBottom,//圖在上文字在下
iconBottomTextTop,//圖在下文字在上
iconLeftTextRight,//圖在左文字在右
iconRightTextLeft,//圖在右文字在左
}
eg1:
IconTextButton.icon(
icon: Icon(Icons.add_alarm,size: 80,),
label: Text("圖下文上"),
color: Colors.lightBlue,
textColor: Colors.white,
elevation: 4.0,
iconTextAlignment: IconTextAlignment.iconBottomTextTop,
onPressed: (){
onClick("圖下文上");
},
),
eg2:
Column(children: <Widget>[
Container(height: 30,),
IconTextButton.icon(
icon: Icon(Icons.add_alarm,size: 80,),
label: Text("圖左文右"),
color: Colors.lightBlue,
textColor: Colors.white,
elevation: 4.0,
iconTextAlignment: IconTextAlignment.iconLeftTextRight,
onPressed: (){
onClick("圖左文右");
},
),
Container(height: 30,),
IconTextButton.icon(
icon: Icon(Icons.add_alarm,size: 80,),
label: Text("圖右文左"),
color: Colors.lightBlue,
textColor: Colors.white,
elevation: 4.0,
iconTextAlignment: IconTextAlignment.iconRightTextLeft,
onPressed: (){
onClick("圖右文左");
},
),
Container(height: 30,),
IconTextButton.icon(
icon: Icon(Icons.add_alarm,size: 80,),
label: Text("圖上文下"),
color: Colors.lightBlue,
textColor: Colors.white,
elevation: 4.0,
iconTextAlignment: IconTextAlignment.iconTopTextBottom,
onPressed: (){
onClick("圖上文下");
},
),
Container(height: 30,),
IconTextButton.icon(
icon: Icon(Icons.add_alarm,size: 80,),
label: Text("圖下文上"),
color: Colors.lightBlue,
textColor: Colors.white,
elevation: 4.0,
iconTextAlignment: IconTextAlignment.iconBottomTextTop,
onPressed: (){
onClick("圖下文上");
},
),
],)
IconTextButton.gif
使用方法:
直接把IconTextButton.dart
文件拖入項目中,然后在使用的文件中導(dǎo)入
import 'package:自己存放的路徑/IconTextButton.dart';
即可使用;
如果不滿足需求秃踩,完全可以在代碼上面直接進(jìn)行需改,
比如:圖片和文字的間隔或者文字和圖片到邊的距離
源碼文件下載地址:
獲取源碼->Flutter
2022-07-28 更新 新版-圖文按鈕
獲取源碼->ImageButton
2019-09-27 更新 IconTextButton升級為 IfeiyvIconTextButton V1.0.1
更新內(nèi)容:
1. IconTextAlignment 添加 noIconOnlyText,//無圖僅包含文字
此時創(chuàng)建的 IfeiyvIconTextButton 的Icon屬性 【必填】可以為 null 也可以是 不為null的Icon
2. 添加 backgroundView 為 IfeiyvIconTextButton 添加一個背景視圖Widget衬鱼,常用來做背景圖片..
如果要使用圓角則可以使用 IfeiyvIconTextButton.icon 中的 shape屬性
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(40.0))),
如果backgroundView是背景圖片可以ClipRRect進(jìn)行切圓角
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(40.0)),
child: Image.asset("images/bg.png",fit: BoxFit.fill,height: 80,),
),
注意:如果 IfeiyvIconTextButton設(shè)置了高度
如:
SizedBox(
height: 80,
child:IfeiyvIconTextButton.icon()
)
如果想要背景view或者背景圖片填充滿,最好高度也設(shè)置一下憔杨,和height高度一致
3. 為了布局更加靈活鸟赫,添加可選參數(shù)
double paddingIconText,// 圖標(biāo)和文字之間的間隔
double paddingLabelToBorder,// 文字到按鈕邊界的間隔
eg:
IfeiyvIconTextButton.icon(
padding: EdgeInsets.all(0),
shape:const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(40.0))),
backgroundView: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(40.0)),
child: Image.asset("images/bg.png",fit: BoxFit.fill,height: 80,),
),
onPressed: (){},
iconTextAlignment: IconTextAlignment.noIconOnlyText,
icon:null,
label: Text("登錄",style: TextStyle(
fontSize: 20,
color: Colors.white
),),
),
test005.gif