默认情况下,flutter中的endDrawer图标是汉堡包图标.我想把它改成过滤器图标.
new Scaffold( endDrawer: Drawer(), ... }
rmtmckenzie.. 18
这应该做你想要的:
import 'package:flutter/material.dart'; class App extends StatefulWidget { @override _AppState createState() => _AppState(); } class _AppState extends State{ @override Widget build(BuildContext context) { return new MaterialApp( home: new Scaffold( endDrawer: Drawer(), appBar: AppBar( actions: [ Builder( builder: (context) => IconButton( icon: Icon(Icons.filter), onPressed: () => Scaffold.of(context).openEndDrawer(), tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip, ), ), ], ), body: new Container(), ), ); } } void main() => runApp(App());
请注意,"构建器"是必需的,以便IconButton获取脚手架下方的上下文.如果没有它,它将改为使用App的上下文,因此无法找到Scaffold.
一个不同的(更干净的?)选项是创建一个包含IconButton的StatelessWidget.
这应该做你想要的:
import 'package:flutter/material.dart'; class App extends StatefulWidget { @override _AppState createState() => _AppState(); } class _AppState extends State{ @override Widget build(BuildContext context) { return new MaterialApp( home: new Scaffold( endDrawer: Drawer(), appBar: AppBar( actions: [ Builder( builder: (context) => IconButton( icon: Icon(Icons.filter), onPressed: () => Scaffold.of(context).openEndDrawer(), tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip, ), ), ], ), body: new Container(), ), ); } } void main() => runApp(App());
请注意,"构建器"是必需的,以便IconButton获取脚手架下方的上下文.如果没有它,它将改为使用App的上下文,因此无法找到Scaffold.
一个不同的(更干净的?)选项是创建一个包含IconButton的StatelessWidget.