[英]How to make a button in Flutter have the same shape as its icon?
您可以使用IconButton()
小部件而不是ElevtaedButton()
以及定義splashRadius
來更改飛濺效果的大小:
IconButton(
splashRadius: 1, // Set the Size of the splash area
color: Colors.grey,
icon: Icon(Icons.backspace),
onPressed: () {},
),
結果:
或者,如果您想使用ElevatedButton()
,請使用.icon
構造函數:
ElevatedButton.icon(
style: ElevatedButton.styleFrom(primary: Colors.grey.shade300),
label: Text('Hello World'),
icon: Icon(
Icons.backspace,
color: Colors.grey,
),
onPressed: () {},
)
結果:
類Icons
中有很多默認圖標不適合您的應用。 您可以使用一些設計平台,例如 Figma,然后將其下載為svg
。 那么代碼可能是:
InkWell(
onTap: () {},
child: SvgPicture.asset(path_to_svg_icon)
)
這樣,您可以為您的圖標編輯顏色、形狀、樣式...。 祝你好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.