我正在使用并通過擴展extendBodyBehindAppBar創建一個. 我在檔案中有一個( ) 圖示,需要單擊它才能打開. 告訴我如何在不使用標準版本的情況下正確實作打開?AppBarPreferredSizeWidgetburgerMenubuttonIconappBarDrawerDrawerAppBar
家
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: LogoAppBar(buttonIcon: SvgPicture.asset(constants.Assets.burgerMenu)),
body: const HomeBody(),
);
}
應用欄
class LogoAppBar extends StatelessWidget with PreferredSizeWidget {
LogoAppBar({Key? key, required this.buttonIcon, this.onPressed})
: super(key: key);
final SvgPicture buttonIcon;
final Function()? onPressed;
@override
Widget build(BuildContext context) {
SvgPicture logoSvg = SvgPicture.asset(
'...logo.svg',
height: 40);
double horizontalPadding = 24;
return SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
logoWidget(logoSvg, horizontalPadding),
SizedBox(child: buttonIcon),
],
),
],
),
),
);
}
Widget logoWidget(SvgPicture logoSvg, double horPadding) {
return Align(
alignment: Alignment.centerLeft,
child: logoSvg,
);
}
@override
Size get preferredSize => const Size.fromHeight(60);
}
uj5u.com熱心網友回復:
您可以使用GlobalKey來打開抽屜并使用 myScaffoldKey.currentState?.openDrawer();。
確保buttonIcon用可點擊的小部件(如GestureDetector/InkWell和 add )包裹你onPressed。
final GlobalKey<ScaffoldState> _sKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _sKey ,
appBar: LogoAppBar(
onPressed: () {
debugPrint("open");
_sKey.currentState?.openDrawer();
},
),
drawer: const Drawer(),
extendBodyBehindAppBar: true,
//...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/465078.html
