title: Closure call with mismatched arguments: function 'LoginScreen.build.<anonymous closure>'
body: <p>Hello I'm getting this error when I tried to run the code</p>
  <p>Here is the full error:</p>
  <pre><code>======== Exception caught by widgets library =======================================================
  The following NoSuchMethodError was thrown building LoginScreen(dirty):
  Closure call with mismatched arguments: function 'LoginScreen.build.&lt;anonymous closure&gt;'
  Receiver: Closure: (String) =&gt; String?
  Tried calling: LoginScreen.build.&lt;anonymous closure&gt;()
  Found: LoginScreen.build.&lt;anonymous closure&gt;(String) =&gt; String?
  
  The relevant error-causing widget was: 
    LoginScreen LoginScreen:file:///C:/Users/diaaa/AndroidStudioProjects/udemy_flutter/lib/main.dart:24:13
  When the exception was thrown, this was the stack: 
  #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:63:5)
  #1      _objectNoSuchMethod (dart:core-patch/object_patch.dart:106:9)
  #2      defaultFormFeild (package:udemy_flutter/shared/components/components.dart:41:26)
  #3      LoginScreen.build (package:udemy_flutter/modules/login/login_screen.dart:31:19)
  #4      StatelessElement.build (package:flutter/src/widgets/framework.dart:4739:28)
  #5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4665:15)
  #6      Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #7      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4643:5)
  #8      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4638:5)
  ...     Normal element mounting (169 frames)
  #177    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3673:14)
  #178    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6333:36)
  #179    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6344:32)
  ...     Normal element mounting (362 frames)
  #541    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3673:14)
  #542    Element.updateChild (package:flutter/src/widgets/framework.dart:3425:18)
  #543    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1198:16)
  #544    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1167:5)
  #545    RenderObjectToWidgetAdapter.attachToRenderTree.&lt;anonymous closure&gt; (package:flutter/src/widgets/binding.dart:1112:18)
  #546    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2573:19)
  #547    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1111:13)
  #548    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:944:7)
  #549    WidgetsBinding.scheduleAttachRootWidget.&lt;anonymous closure&gt; (package:flutter/src/widgets/binding.dart:924:7)
  (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
  ====================================================================================================
  
  ======== Exception caught by widgets library =======================================================
  The following NoSuchMethodError was thrown building LoginScreen(dirty):
  Closure call with mismatched arguments: function 'LoginScreen.build.&lt;anonymous closure&gt;'
  Receiver: Closure: (String) =&gt; String?
  Tried calling: LoginScreen.build.&lt;anonymous closure&gt;()
  Found: LoginScreen.build.&lt;anonymous closure&gt;(String) =&gt; String?
  
  The relevant error-causing widget was: 
    LoginScreen LoginScreen:file:///C:/Users/diaaa/AndroidStudioProjects/udemy_flutter/lib/main.dart:24:13
  When the exception was thrown, this was the stack: 
  #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:63:5)
  #1      _objectNoSuchMethod (dart:core-patch/object_patch.dart:106:9)
  #2      defaultFormFeild (package:udemy_flutter/shared/components/components.dart:41:26)
  #3      LoginScreen.build (package:udemy_flutter/modules/login/login_screen.dart:31:19)
  #4      StatelessElement.build (package:flutter/src/widgets/framework.dart:4739:28)
  #5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4665:15)
  #6      Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #7      StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
  #8      Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #9      SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #10     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #11     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #12     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #13     StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
  #14     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #15     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #16     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #17     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #18     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #19     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #20     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
  #21     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #22     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
  #23     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #24     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #25     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #26     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #27     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #28     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #29     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
  #30     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #31     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
  #32     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #33     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #34     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #35     StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
  #36     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #38     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
  #39     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #40     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
  #41     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #42     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #43     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #44     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #45     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #46     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #47     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #48     ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
  #49     _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:181:11)
  #50     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #51     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #52     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #53     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #54     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
  #55     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #56     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
  #57     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #58     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #59     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #60     ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
  #61     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #62     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #63     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #64     ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
  #65     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #66     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #67     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
  #68     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #69     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
  #70     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #71     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #72     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #73     StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
  #74     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #75     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #76     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #77     StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
  #78     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #79     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
  #80     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #81     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #82     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #83     ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
  #84     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #85     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #86     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #87     ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
  #88     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #89     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #90     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
  #91     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #92     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
  #93     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #94     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #95     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
  #96     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #97     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
  #98     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
  #99     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
  #100    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
  #101    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
  #102    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2620:33)
  #103    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
  #104    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
  #105    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
  #106    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
  #107    SchedulerBinding.scheduleWarmUpFrame.&lt;anonymous closure&gt; (package:flutter/src/scheduler/binding.dart:863:7)
  (elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
  ====================================================================================================
  </code></pre>
  <p>My LoginScreen code:</p>
  <pre><code>import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  import 'package:udemy_flutter/shared/components/components.dart';
  class LoginScreen extends StatelessWidget {
    var emailController = TextEditingController();
    var passController = TextEditingController();
    var formKey = GlobalKey&lt;FormState&gt;();
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(),
        body: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Center(
            child: SingleChildScrollView(
              child: Form(
                key: formKey,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text(
                        'Login',
                      style: TextStyle(
                        fontSize: 40.0,
                        fontWeight: FontWeight.bold
                      ),
                    ),
                    const SizedBox(
                      height: 40.0,
                    ),
                    defaultFormFeild(
                        controller: emailController,
                        label: 'Email',
                        prefix: Icons.email,
                        type: TextInputType.emailAddress,
                        validate: (String value){
                          if(value.isEmpty != null){
                            return 'Email Cannot Be Empty';
                          }
                          return null;
                        }
                    ),
                    const SizedBox(
                      height: 15.0,
                    ),
                    TextFormField(
                      controller: passController,
                      obscureText: true,
                      keyboardType: TextInputType.visiblePassword,
                      decoration: const InputDecoration(
                        border: OutlineInputBorder(),
                        labelText: 'Password',
                        prefixIcon: Icon(
                          Icons.lock
                        ),
                        suffixIcon: Icon(
                          Icons.remove_red_eye,
                        )
                      ),
                      onChanged: (value) {
                        print(value);
                      },
                      onFieldSubmitted: (value) {
                        print(value);
                      },
                      validator: (value) {
                        if(value!.isEmpty){
                          return 'Password cannot be empty';
                        }
                        return null;
                      },
                    ),
                    const SizedBox(
                      height: 10.0,
                    ),
                    defaultButton(
                      function: (){
                        print(emailController.text);
                        print(passController.text);
                      },
                      text: 'Login',
                    ),
                    const SizedBox(
                      height: 10.0,
                    ),
                    defaultButton(
                      text: 'ReGister',
                      function: () {
                        print('You have just clicked on register');
                      },
                      background: Colors.red,
                      isUpperCase: false
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        const Text('Don\'t you have an account?'),
                        TextButton(onPressed: () {}, child: const Text(
                          'Register Now'
                        ))
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        ),
      );
    }
  }
  </code></pre>
  <p>My main.dart code:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:udemy_flutter/modules/bmi_result/bmi_result_screen.dart';
  import 'modules/bmi_result/bmi_result_screen.dart';
  import 'modules/bmi/bmi_screen.dart';
  import 'modules/home/home_screen.dart';
  import 'modules/login/login_screen.dart';
  import 'modules/messenger/messenger_screen.dart';
  import 'modules/users/users_screen.dart';
  import 'modules/counter/counter_screen.dart';
  
  void main() {
    runApp(MyApp());
    MyApp app = MyApp();
  }
  
  //Stateless widget
  //Stateful widget
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: LoginScreen(),
      );
    }
  }
  </code></pre>
  <p>EDIT:
  I have this code in a separate file called components.dart</p>
  <pre><code>import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  
  Widget defaultButton(
      {double width = double.infinity,
        Color background = Colors.blue,
        double radius = 10.0,
        required Function function,
        required String text,
        bool isUpperCase = true}) =&gt;
      Container(
        height: 40.0,
        width: width,
        child: MaterialButton(
            onLongPress: () {},
            onPressed: function(),
            child: Text(
              isUpperCase ? text.toUpperCase() : text.toLowerCase(),
              style: TextStyle(color: Colors.white),
            )),
        decoration: BoxDecoration(
          borderRadius: BorderRadiusDirectional.circular(radius),
          color: background,
        ),
      );
  
  Widget defaultFormFeild({
    required TextEditingController controller,
    required TextInputType type,
    Function? onSubmit, //Add question mark
    Function? onChange, //Add question mark
    required Function validate,
    required var label,
    required IconData prefix,
  }) =&gt;
      TextFormField(
        controller: controller,
        keyboardType: type,
        onFieldSubmitted: onSubmit != null? onSubmit() : null, //do null checking
        onChanged: onChange != null? onChange() : null, //do null checking
        validator: validate(),
        decoration: InputDecoration(
            labelText: label,
            prefixIcon: Icon(prefix),
            border: OutlineInputBorder()
        ),
      );
  </code></pre>
  <p><em><strong>can someone tell me where I am going wrong</strong></em>
  I'm new to the Flutter platform and I'm trying to build screens for various uses as I was having problems with Null safety and I managed to solve it, but I didn't know exactly what the problem with this code was</p>