我不知道如何将appBar的自动后退按钮更改为不同的颜色。它在脚手架下,我试图研究它,但我无法理解它。

return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: Image.asset(
          'images/.jpg',
          fit: BoxFit.fill,
        ),
        centerTitle: true,
      ),

当前回答

全局设置后退按钮颜色

MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        appBarTheme: AppBarTheme(
          backgroundColor: Colors.white,
          iconTheme: IconThemeData(color: Colors.black), // set backbutton color here which will reflect in all screens. 
        ),
      ),
      home: LoginScreen(),
    );

同时,

更改SliverAppBar

 SliverAppBar(
            iconTheme: IconThemeData(
              color: Colors.white, //change your color here
            ),

其他回答

在AppBar中,添加前导参数并分配BackButton小部件。然后将颜色参数添加到BackButton,如下所示:

AppBar(
  leading: const BackButton(
    color: Colors.black, // Change the color here
  ),
  centerTitle: true,
)

你必须使用AppBar中的iconTheme属性,像这样:

appBar: AppBar(
  iconTheme: IconThemeData(
    color: Colors.black, //change your color here
  ),
  title: Text("Sample"),
  centerTitle: true,
),

或者你想自己操作后退按钮。

appBar: AppBar(
  leading: IconButton(
    icon: Icon(Icons.arrow_back, color: Colors.black),
    onPressed: () => Navigator.of(context).pop(),
  ), 
  title: Text("Sample"),
  centerTitle: true,
),

更好的是,只有当你想改变后退按钮的颜色时才可以这样做。

appBar: AppBar(
  leading: BackButton(
     color: Colors.black
   ), 
  title: Text("Sample"),
  centerTitle: true,
),

更改CupertinoPageScaffold的主色调

Theme(
  data: Theme.of(context).copyWith(
    cupertinoOverrideTheme: CupertinoThemeData(
      scaffoldBackgroundColor: Colors.white70,
      primaryColor: Styles.green21D877, // HERE COLOR OF LEADING
    ),
  ),
  child: CupertinoPageScaffold(
    navigationBar: CupertinoNavigationBar(
      brightness: Brightness.light,
      backgroundColor: Colors.white,
      middle: Text('Cupertino App Bar'),
    ),
    child: Container(
      child: Center(
        child: CupertinoActivityIndicator(),
      ),
    ),
  ),
)

你也可以通过'leading'来覆盖默认的后退箭头:

leading: new IconButton(
  icon: new Icon(Icons.arrow_back, color: Colors.orange),
  onPressed: () => Navigator.of(context).pop(),
), 

AppBar小部件所做的就是在没有设置的情况下提供一个默认的“leading”小部件。

它似乎更容易只是创建一个新的按钮,并添加颜色,这里我是如何做的任何人都想知道

Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(
            color: Colors.black
        ),