Home > Software design >  How to change the function of the back button in the flutter app bar? SOLVED
How to change the function of the back button in the flutter app bar? SOLVED

Time:10-22

How can I change the function of the back button in de app bar? So I want to go to the home page when you click on the back button how can I make this work?

 appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        leading: const BackButton(
          color: Color(0xFFFD879A),
        ),
      ),

CodePudding user response:

Add onPressed to your leading:

leading: BackButton(
  color: Color(0xFFFD879A),
  onPressed: () {
    // do your navigate here

    print("back click");
  },
),

CodePudding user response:

 appBar: AppBar(
    backgroundColor: Colors.transparent,
    elevation: 0,
    leading: const BackButton(
      color: Color(0xFFFD879A),
      onPressed: () {
          // execute this on pressed...
      },
    ),
  ),
  • Related