Android_devNL
Android_devNL

Reputation: 147

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

Upvotes: 0

Views: 1549

Answers (2)

mfrischbutter
mfrischbutter

Reputation: 96

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

Upvotes: 1

eamirho3ein
eamirho3ein

Reputation: 17950

Add onPressed to your leading:

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

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

Upvotes: 3

Related Questions