抽屉具有默认的三个水平栏作为默认图标,但我想将其更改为其他内容。
我已经检查了下可能的选项Drawer()
,但似乎没有任何财产与之相关。
这应该有效。
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title:Text('hi'),
leading: IconButton(
icon: Icon(Icons.accessible),
onPressed: () => Scaffold.of(context).openDrawer(),
),
),
);
从文档 ->
{Widget领先} 类型:Widget
显示在[标题]之前的小部件。
如果该值为 null 并且 [automaticallyImplyLeading] 设置为 true,则 [AppBar] 将暗示适当的小部件。例如,如果 [AppBar] 位于也有 [Drawer] 的 [Scaffold] 中,则 [Scaffold] 将使用打开抽屉的 [IconButton](使用 [Icons.menu])填充此小部件。如果没有 [Drawer] 并且父级 [Navigator] 可以返回,则 [AppBar] 将使用调用 [Navigator.maybePop] 的 [BackButton]。
以下代码显示了如何手动指定抽屉按钮而不是依赖 [automaticallyImplyLeading]:
import 'package:flutter/material.dart';
Widget build(context) {
return AppBar(
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: const Icon(Icons.menu),
onPressed: () {
Scaffold.of(context).openDrawer();
},
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
);
},
),
);
}
本示例中使用 [Builder] 来确保上下文引用子树的该部分。这样,即使在创建 [Scaffold] 的代码内部也可以使用此代码片段(在这种情况下,如果没有 [Builder],上下文将无法看到 [Scaffold],因为它会引用该小部件的祖先)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)