
這是我的按鈕組件代碼:
Widget build(BuildContext context) {
return MaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(40)),
side: BorderSide(color: kPrimaryColor)
),
padding: padding,
color: color,
minWidth: 280,
onPressed: press,
child: Text(
text,
style: TextStyle(
color: Colors.grey[900],
fontSize: 15,
),
),
);
}
uj5u.com熱心網友回復:
child用 a包裹您Row并將圖示添加為您的 Row 的第二個元素children。它會變成如下所示:
child: Row(
children: [
Text(
text,
style: TextStyle(
color: Colors.grey[900],
fontSize: 15,
),
),
Image.asset('assets/icons/my_icon.png'),
],
),
uj5u.com熱心網友回復:
您可以使用 TextButton.icon 小部件
并翻轉標簽和圖示(都接受小部件)
TextButton.icon(
icon: Text("MyText",
style: TextStyle(
fontSize: 11.0,
fontFamily: "Raleway"
),
),
label: Image.asset('assets/myImage.png', width: 20.0,height: 20.0,),
style: ButtonStyle(
// backgroundColor:
// MaterialStateProperty.all(Colors.green.shade200),
overlayColor: MaterialStateProperty.all(Colors.green),
side: MaterialStateProperty.resolveWith((states) {
return BorderSide(color: Colors.grey, width: 1);
})),
)
uj5u.com熱心網友回復:
在 中TextButton,我設法添加了一行,其中包含icon和text
TextButton(
onPressed: (){},
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Icons.arrow_back_ios,
color: Themes.primaryColor,
),
Text(
'Back',
style: TextStyle(
fontSize: 17,
color: Themes.primaryColor,
),
),
],
),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/342564.html
上一篇:自定義AppBar元素型別'List<dynamic>'不能分配給串列型別
下一篇:Dart:如何正確處理空安全?
