How to change the appBar back button color

前端 未结 9 629
慢半拍i
慢半拍i 2021-01-30 11:54

I cannot figure out how to change the appBar\'s automatic back button to a different color. it\'s under a scaffold and I\'ve tried to research it but I can\'t wrap my head aroun

9条回答
  •  囚心锁ツ
    2021-01-30 12:49

    You have to use the iconTheme property from the AppBar , like this:

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

    Or if you want to handle the back button by yourself.

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

    Even better, only if you want to change the color of the back button.

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

提交回复
热议问题