skip to Main Content

I have a standard ElevatedButton action:

                    ElevatedButton(
                      onPressed: () => myPolicySet.serialize(),
                      child: const Text('serialize'),
                    ),

I also want it to navigate to a new page:

                    ElevatedButton(
                      onPressed: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => const DiagramAppTwo()),
                      },
                      child: const Text('serialize'),
                    ),

Is this possible? if so, how should I do it?

2

Answers


  1. you’re free to setup a how much actions you want

    like: onPressed: () { FirstAction(); SecondAction();}

    in your example,it should be :

            ElevatedButton(
                              onPressed: () {
                               myPolicySet.serialize();
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) => const DiagramAppTwo());
                              },
                              child: const Text('serialize'),
                            ),
    
    Login or Signup to reply.
  2. Can’t you make a separate function and pass to onPressed?? And in that function you can write the code for both.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search