Home > Net >  how to call another page (class) if user pressed the button? (flutter)
how to call another page (class) if user pressed the button? (flutter)

Time:10-12

What to put inside onPressed to call another page, for example I want to call class_one() after I press the button, what is the solution for it?

                                  Padding(
                                        padding: const EdgeInsets.all(8.0),
                                        child: ElevatedButton(
                                          onPressed: () {
                         
                                            // Respond to button press
                                          },
                                          child: Text('Kehadiran Anggota'),
                                        )),

CodePudding user response:

You can use the pushNamed function like this:
Navigator.of(context).pushNamed('/yourScreen');
In order for it to work you need to register the route inside MaterialApp like this:

MaterialApp(routes: {
  '/': (context) => TelaSplashScreen(),
},)

CodePudding user response:

You can use the code below to navigate between pages, with Navigator.push() you will be able to go next page and back and with Navigator.pushReplacement() it will proceed to next page but loses its capability to go back to previous page.

Navigator.push(
   context,
   MaterialPageRoute(
      builder: (context) => const MemberAttendancePage(),
   ),
);
  • Related