Search code examples
flutterdartflutter-layoutappbar

How to change the function of the back button in the flutter app bar?


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),
        ),
      ),

Solution

  • Add onPressed to your leading:

    leading: BackButton(
      color: Color(0xFFFD879A),
      onPressed: () {
        // do your navigate here
    
        print("back click");
      },
    ),