title: How to add a required parameter in flutter
body: <p>I am creating an authentication page in flutter using <a href="https://github.com/abuanwar072/Welcome-Login-Signup-Page-Flutter" rel="nofollow noreferrer">this github repository</a>. I have managed to get rid of most errors. I have a <strong>body.dart</strong> file that imports from other files one of them being <strong>background.dart</strong> that has a constructor with required parameters. Using a widget in <strong>body.dart</strong> brings up the error</p>
  <pre><code>The named parameter 'key' is required, but there's no corresponding argument.
  Try adding the required argument.dart(missing_required_argument)
  </code></pre>
  <p>These are the code:
  <strong>background.dart</strong></p>
  <pre><code>import 'package:flutter/material.dart';
  class Background extends StatelessWidget {
    final Widget child;
    const Background({
      //added required to the key and child
      required Key key,
      required this.child,
    }) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      Size size = MediaQuery.of(context).size;
      return Container(
        height: size.height,
        width: double.infinity,
        child: Stack(
          alignment: Alignment.center,
          children: &lt;Widget&gt;[
            Positioned(
              top: 0,
              left: 0,
              child: Image.asset(
                &quot;assets/images/main_top.png&quot;,
                width: size.width * 0.3,
              ),
            ),
            Positioned(
              bottom: 0,
              left: 0,
              child: Image.asset(
                &quot;assets/images/main_bottom.png&quot;,
                width: size.width * 0.2,
              ),
            ),
            child,
          ],
        ),
      );
    }
  }
  </code></pre>
  <p><strong>body.dart</strong></p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:meekap/Screens/Welcome/components/background.dart';
  import 'package:meekap/Screens/Login/login_screen.dart';
  import 'package:meekap/Screens/Signup/signup_screen.dart';
  import 'package:meekap/components/rounded_button.dart';
  import '../../../constants.dart';
  
  class Body extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      Size size = MediaQuery.of(context).size;
      // This size provide us total height and width of our screen
      return Background(//Error comes up here
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: &lt;Widget&gt;[
              Text(
                &quot;Welcome to meeKap&quot;,
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
              SizedBox(height: size.height * 0.05),
              Image.asset(
                &quot;assets/icons/chat.svg&quot;,
                height: size.height * 0.45,
              ),
              SizedBox(height: size.height * 0.05),
              RoundedButton(//Error comes up here
                text: &quot;LOGIN&quot;,
                press: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) {
                        return LoginScreen();
                      },
                    ),
                  );
                },
              ),
              RoundedButton(
                text: &quot;SIGN UP&quot;,
                color: kPrimaryLightColor,
                textColor: Colors.black,
                press: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) {
                        return SignUpScreen();
                      },
                    ),
                  );
                },
              ),
            ],
          ),
        ),
      );
    }
  }
  
  
   
  </code></pre>