颤振导航抽屉汉堡包图标颜色变化

Amm*_*ang 8 navigation-drawer flutter flutter-layout

导航抽屉的汉堡图标颜色没有变化.它默认为黑色.我想改变这个图标颜色颤动,我卡住了,帮我改变这个图标颜色.这是我的代码.

class Test extends StatefulWidget {
@override
_TestState createState() => new _TestState();
}

class _TestState extends State<Test> {


    @override
    Widget build(BuildContext context) {
    return new Scaffold(

    drawer: new Drawer(),
    appBar: new AppBar(
    title: new Text("Navigation Drawer")
        ),
       ),
     );
    }
 }
Run Code Online (Sandbox Code Playgroud)

Phu*_*ran 33

iconTheme添加到AppBar

@override
Widget build(BuildContext context) {
  return new Scaffold(
    drawer: new Drawer(),
    appBar: new AppBar(
      title: new Text("Navigation Drawer"),
      iconTheme: new IconThemeData(color: Colors.green),
    ),
  );
}
Run Code Online (Sandbox Code Playgroud)

  • 在 Flutter 中启用 useMaterial3 时,此方法不起作用。无需启用 Material 3 即可工作 (4认同)

Cop*_*oad 13

您还可以使用以下 inThemedata属性

Theme(
  data: ThemeData(primaryIconTheme: IconThemeData(color: Colors.red)), // use this
  child: Scaffold(),
)
Run Code Online (Sandbox Code Playgroud)

或者

appBar: AppBar(
  leading: IconButton(
    icon: Icon(Icons.menu, color: Colors.red), // set your color here
    onPressed: () {},
  ),
),
Run Code Online (Sandbox Code Playgroud)


kis*_*rma 5

要更改图标的颜色,请使用此

  @override
  Widget build(BuildContext context) {
   return new MaterialApp(
   home: new Scaffold(
    appBar: AppBar(title: new Text('List view example'),
      leading: new Icon(Icons.menu,color: Colors.green,),
   ),
),
 );
 }
Run Code Online (Sandbox Code Playgroud)

Icon(Icons.menu,color: Colors.green,) 定义图标内的颜色