title: How to show an alert dialog after the user click the button in flutter
body: <p>I'm new in flutter and I'm trying to show a dialog alert for the result if the user click on &quot;Calculate&quot; button. I want to change the &quot;Text&quot; result into the dialog alert like &quot;The prediction of (total days) is (result)&quot; Anyone can help me how to do this? I can't find any suitable resource for this, Thank you</p>
  <pre><code>class TransactionYearly extends StatefulWidget {
    @override
    _TransactionYearlyState createState() =&gt; _TransactionYearlyState();
  }
  
  class _TransactionYearlyState extends State&lt;TransactionYearly&gt; {
    final GlobalKey&lt;FormState&gt; _formKey = GlobalKey&lt;FormState&gt;();
    final TextEditingController amount = new TextEditingController();
  
    final TextEditingController  day = new TextEditingController();
  
    double _result;
  
    @override
    void initState() {
      super.initState();
    }
    @override
    void dispose() {
      super.dispose();
    }
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(getTranslated(context, 'prediction_calculation'),),
          elevation: 0,
          brightness: Brightness.light,
          backgroundColor: primary,
          leading: IconButton(
            onPressed: (){
              Navigator.pop(context, MaterialPageRoute(builder: (context) =&gt; Transactions()));
            },
            icon: Icon(Icons.arrow_back_ios,
              size: 20,
              color: Colors.black,),
          ),
        ),
          body: SingleChildScrollView(
            child: Container(
              child: Column(
                children: &lt;Widget&gt;[
                  Container(
                    height: 300,
                    child: Image(
                      image: AssetImage(&quot;assets/girlsave.png&quot;),
                      fit: BoxFit.contain,
                    ),
                  ),
                  Container(
                    child: Form(
                      key: _formKey,
                      child: Column(
                        children: &lt;Widget&gt;[
                          Container(
                            child: TextFormField(
                                validator: (input) {
                                  if (input.isEmpty) return 'Please fill up the text fields';
                                },
                              controller: amount,
                                decoration: InputDecoration(
                                  labelText: getTranslated(context, 'amount_text'),
                                  labelStyle: TextStyle(color: Colors.grey),
                                  prefixIcon: Icon(
                                    Icons.attach_money,
                                    color: secondary,
                                  ),
                                  focusedBorder: UnderlineInputBorder(
                                    borderSide: BorderSide(color: secondary),
                                  ),
                                ),
  
                              keyboardType: TextInputType.number,
                            ),
                          ),
                          Container(
                            child: TextFormField(
                                validator: (input) {
                                  if (input.isEmpty)
                                    return 'Please fill up the text fields';
                                },
                              controller: day,
                                decoration: InputDecoration(
                                  labelText: getTranslated(context, 'day_text'),
                                  labelStyle: TextStyle(color: Colors.grey),
                                  prefixIcon: Icon(
                                    Icons.date_range_outlined,
                                    color: secondary,
                                  ),
                                  focusedBorder: UnderlineInputBorder(
                                    borderSide: BorderSide(color: secondary),
                                  ),
                                ),
  
                              keyboardType: TextInputType.number,
                            ),
                          ),
                          SizedBox(height: 20),
                          Container(
                                padding: EdgeInsets.only(
                                    top: 25.0, left: 20.0, right: 20.0),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: &lt;Widget&gt; [
                                  Expanded (
                                    child: ElevatedButton(
  
                                      onPressed: () {
                                        if(!_formKey.currentState.validate()){
                                          return;
                                        }
                                        _formKey.currentState.save();
                                        calculate();
                                      },
                                      child: Text(getTranslated((context), &quot;calculate_button&quot;).toUpperCase(), style: TextStyle (
                                        fontSize: 14,
                                      )),
                                      style: ButtonStyle(
                                        padding: MaterialStateProperty.all&lt;EdgeInsets&gt;(EdgeInsets.all(15)),
                                        foregroundColor: MaterialStateProperty.all&lt;Color&gt;(Colors.white),
                                        backgroundColor: MaterialStateProperty.all&lt;Color&gt;(Colors.pink),
                                        shape: MaterialStateProperty.all&lt;RoundedRectangleBorder&gt;(
                                          RoundedRectangleBorder(
                                              borderRadius: BorderRadius.circular(15.0),
                                              side: BorderSide(color: secondary)
                                          ),
                                        ),
                                      ),
  
                                    ),
                                  ),
                                  SizedBox(width: 20, height: 10),
                                  Expanded(
                                    child: ElevatedButton(
                                      onPressed: () {
                                        amount.clear();
                                        day.clear();
                                      },
                                      child: Text(getTranslated((context), &quot;clear_button&quot;).toUpperCase(), style: TextStyle (
                                          fontSize: 14
                                      )),
                                      style: ButtonStyle(
                                        padding: MaterialStateProperty.all&lt;EdgeInsets&gt;(EdgeInsets.all(15)),
                                        foregroundColor: MaterialStateProperty.all&lt;Color&gt;(Colors.white),
                                        backgroundColor: MaterialStateProperty.all&lt;Color&gt;(Colors.pink),
                                        shape: MaterialStateProperty.all&lt;RoundedRectangleBorder&gt;(
                                          RoundedRectangleBorder(
                                              borderRadius: BorderRadius.circular(15.0),
                                              side: BorderSide(color: secondary)
                                          ),
                                        ),
                                      ),
                                    ),
                                  )
                                ],
                              )
                          ),
                          Text(
                            _result == null ? &quot;Enter amount&quot; : &quot;$_result&quot;,
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ));
    }
    void calculate(){
      double amounts = double.parse(amount.text);
      double days = double.parse(day.text);
  
      double result = amounts * days;
      _result = result;
      setState(() {
  
      });
    }
  }
  </code></pre>