Boby
Boby

Reputation: 1202

Do i need to configure my back button in appbar manually?

I'm trying to open my other class with this

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

Here is the class that i want open

class ProjectDetail extends StatefulWidget {
  @override
  _ProjectDetailState createState() => new _ProjectDetailState();
}

class _ProjectDetailState extends State<ProjectDetail> {
  final List<Project> projects;
  _ProjectDetailState({Key key, this.projects});
  @override
  Widget build(BuildContext context) {
    return  MaterialApp(
        title: 'Task Management System',
        home: Scaffold(
          appBar: AppBar(

            title: Text("Sample"),
            centerTitle: true,
          ),
            body:
            Center(
                child:Text("Hello")
            )
        ),
    );
  }

So, when i open the class the is no back button. But when i add the script below, the back button is showing up.

leading: new IconButton(
              icon: new Icon(Icons.arrow_back),
              color: Colors.white,
              onPressed: () => Navigator.of(context).pop(),
            ),

I'm new with flutter. Is it possible to show the back button it self without write another script ? did i miss something ?

Upvotes: 1

Views: 154

Answers (1)

Azamat Ahunjanov
Azamat Ahunjanov

Reputation: 366

Where is the class where you call push method? Try add to MaterialApp

routes: {
            '/detail': (BuildContext context) => ProjectDetail() ,
}

and call with

Navigator.pushNamed(context, '/detail');

Upvotes: 2

Related Questions