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(
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.
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. 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:
AppBar(
leading: ModalRoute.of(context)?.canPop == true
? IconButton(
icon: Icon(
Icons.arrow_back,
size: 60,
onPressed: () => Navigator.of(context).pop(),
),
)
: null,
title: Text(
"Example",
),
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.