[英]How can I change the size of drawer/back button icons of appbar without modifying the behavior provided by default in Flutter?
I am trying to change the size of the icons ("Back" provided by Navigator and "Drawer" provided by Scaffold) in appbar in my ThemeData, modifying iconTheme and primaryIconTheme:我试图在我的 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)
),
This lines only changes the color of the icons, but the size does not change.此行仅更改图标的颜色,但大小不会更改。
I do not need to change the behavior that Flutter handles this button, only the size of them.我不需要改变 Flutter 处理这个按钮的行为,只需要改变它们的大小。
The AppBar widget uses a BackButton widget, so that change is not possible unless you modify it from the framework in a different branch, but the best approach is to use the Leading property and the condition ModalRoute.of(context)?.canPop to check whether the current route can be popped. AppBar 小部件使用BackButton小部件,因此除非您从不同分支中的框架修改它,否则无法进行更改,但最好的方法是使用 Lead 属性和条件 ModalRoute.of(context)?.canPop 来检查当前路由是否可以弹出。 For example:
例如:
AppBar( leading: ModalRoute.of(context)?.canPop == true ? IconButton( icon: Icon( Icons.arrow_back, size: 60, ), ) : null, title: Text( "Example", ), )
Luis' answer is mostly complete, but note that you will need to define the onPressed
callback in the IconButton, shown below: 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.