'Cant return form after a DialogOption is clicked in flutter

I am trying to to return form after a SimpleDialogOption is clicked in flutter there is actually no error but I cant see the form. my code

SimpleDialogOption(
           padding: EdgeInsets.symmetric(horizontal: 24,vertical: 14),
           onPressed: (){ 
            Navigator.of(context).pop();
             _Transaction();
           },
           child: Text('Transaction'),
         ),


Form _Transaction(){
    return Form(
      key: _formKey,
      child: Column(
        children: <Widget>[
          const Text('On What did you spend?', 
          style: TextStyle(fontSize: 16),)
        ],
      )
      );
  }


Solution 1:[1]

class MyHomePage extends StatefulWidget {
  final String title;

  const MyHomePage({
    Key? key,
    required this.title,
  }) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

    bool showForm=false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
              // you code here
       //         SimpleDialogOption(
        //   padding: EdgeInsets.symmetric(horizontal: 24,vertical: 14),
        //   onPressed: (){ 
        //   setState(()=>showForm=!showForm);  
        //  Navigator.of(context).pop();
         //    
         //  },
         //  child: Text('Transaction'), ),
         //
             TextButton(
              onPressed:(){
                 setState(()=>showForm=!showForm);
             
              },
              child:Text("show form")
            ),
            if(this.showForm)_Transaction()
          ],
        ),
      ),
     
    );
  }
  Form _Transaction(){
    return Form(
      child: Column(
        children: <Widget>[
          const Text('On What did you spend?', 
          style: TextStyle(fontSize: 16),)
        ],
      )
      );
  }
}

Solution 2:[2]

I solved it by adding return inside on pressed(){} my code now looks like this:

onPressed: (){ 
            Navigator.of(context).pop();
             _Transaction();
           },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Salim Baskoy
Solution 2 Shree Mahadik