[英]How can I change the size of drawer/back button icons of appbar without modifying the behavior provided by default in Flutter?
我試圖在我的 ThemeData 的應用欄中更改圖標的大小(由 Navigator 提供的“Back”和由 Scaffold 提供的“Drawer”),修改 iconTheme 和 primaryIconTheme:
ThemeData(
primarySwatch: Colors.blue,
iconTheme: IconThemeData(color: Colors.grey, size: 32),
primaryIconTheme: IconThemeData(color: Colors.grey, size: 32)
),
此行僅更改圖標的顏色,但大小不會更改。
我不需要改變 Flutter 處理這個按鈕的行為,只需要改變它們的大小。
AppBar 小部件使用BackButton小部件,因此除非您從不同分支中的框架修改它,否則無法進行更改,但最好的方法是使用 Lead 屬性和條件 ModalRoute.of(context)?.canPop 來檢查當前路由是否可以彈出。 例如:
AppBar( leading: ModalRoute.of(context)?.canPop == true ? IconButton( icon: Icon( Icons.arrow_back, size: 60, ), ) : null, title: Text( "Example", ), )
Luis 的回答大部分是完整的,但請注意,您需要在onPressed
中定義onPressed
回調,如下所示:
AppBar(
leading: ModalRoute.of(context)?.canPop == true
? IconButton(
icon: Icon(
Icons.arrow_back,
size: 60,
onPressed: () => Navigator.of(context).pop(),
),
)
: null,
title: Text(
"Example",
),
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.