title: Using Type Function and pass it into ElevatedButton onPressed, Flutter
body: <p>I am new to Flutter + Dart. I basically have class in the following.
  First I have a clas called BottomForm where it have build function that returns ElevatedButton problem when I call Function type variable in onPressed I have an issue saying that:
  The argument type 'Function' can't be assigned to the parameter type 'void Function()?'.dartargument_type_not_assignable</p>
  <pre><code>import 'formbutton.dart';
  
  // Define a corresponding State class.
  // This class holds the data related to the Form.
  class _MyCustomFormState extends State&lt;MyCustomForm&gt; {
    // Create a text controller and use it to retrieve the current value
    // of the TextField.
    final email = TextEditingController();
    final password = TextEditingController();
  
    void _logIn() {
      
      print(&quot;Logged In.&quot;);
    }
  
    @override
    void dispose() {
      // Clean up the controller when the widget is disposed.
      email.dispose();
      password.dispose();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: TextFormField(
                autocorrect: true,
                controller: email,
              ),
            ),
            ButtonForm(_logIn, &quot;Hello&quot;),
          ],
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            showDialog(
                context: context,
                builder: (context) {
                  return AlertDialog(
                    content: Text(email.text),
                  );
                });
          },
          tooltip: &quot;Show me the value&quot;,
          child: Icon(Icons.text_fields),
        ),
      );
    }
  }
  
  //Define a Custom Widget
  class MyCustomForm extends StatefulWidget {
    @override
    _MyCustomFormState createState() =&gt; _MyCustomFormState();
  }
  </code></pre>
  <p>Than I have a problem in the main class for our Button . When I pass the Function functionApply;</p>
  <pre><code>import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  
  class ButtonForm extends StatelessWidget {
    final Function functionApply;
  
    final String textButton;
  
    ButtonForm(this.functionApply, this.textButton);
  
    @override
    Widget build(BuildContext context) {
      return Container(
        width: double.infinity,
        child: ElevatedButton(
          child: Text(this.textButton),
          onPressed: this.functionApply, // I have a problem here!! 
        ),
      );
    }
  }
  </code></pre>