Ad

Flutter: How To Change The Icon Returned By Navigation?

- 1 answer

I am new in Flutter. I want to change the icon returned by navigation.

Screen1 Code:

Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) => Screen2(),
  ),
);

Screen2 Code:

Scaffold(
  appBar: AppBar(),
  body: Container(),
),
Ad

Answer

The AppBar() widget has a leading property where you can customize the navigation icon.

Here's an example:

      AppBar(
        leading: IconButton(
            onPressed: () {
              Navigator.pop(context);
            },
            icon: const Icon(
              Icons.menu_rounded,
            ),
         ),
      ),

Check this helpful documentation for Material App Bars: https://material.io/components/app-bars-top/flutter

Ad
source: stackoverflow.com
Ad