在AppBar的父级组件中设置AppBarTheme,然后将其中的颜色属性设置为想要的导航栏颜色。示例代码如下:
AppBar(
title: Text('My App'),
backgroundColor: Colors.green,
elevation: 0,
),
// 修改为:
Theme(
data: Theme.of(context).copyWith(
appBarTheme: AppBarTheme(
color: Colors.green, // 修改导航栏颜色
),
),
child: Scaffold(
appBar: AppBar(
title: Text('My App'),
elevation: 0,
),
),
);