I'm making a login page in a flutter app which requires a constructor that takes too parameters ( goToWelcomeListener, enterAnimation ) as shown:

    abstract class GoToWelcomeListener {
      void onGoToWelcomeTap();
    }

    class LoginScreen extends StatefulWidget {

    final GoToWelcomeListener goToWelcomeListener;
    final LoginEnterAnimation enterAnimation;

   LoginScreen(
     {@required AnimationController controller,
     @required this.goToWelcomeListener})
    : this.enterAnimation = new LoginEnterAnimation(controller);

  State<StatefulWidget> createState() {
   return new LoginScreenState();
   }
  }

  class LoginScreenState extends State<LoginScreen> {

  final GoToWelcomeListener goToWelcomeListener;
  final LoginEnterAnimation enterAnimation;
  final userNameController = TextEditingController();
  final passwordController = TextEditingController();
  final formKey = GlobalKey<FormState>();
  final URL = "https://gam3ity.com/";

  LoginScreenState(
    {@required AnimationController controller,
    @required this.goToWelcomeListener})
    : this.enterAnimation = new LoginEnterAnimation(controller);

And as you can see i had to define the constructor two times for it to work and not give me errors, because if i defined it just in the state itself and not the class, it doesn't recognize it as a constructor, and if i declared it in the class without the state, i can't use any of the parameters in the state cuz it's initialized in the class not the state.

Then when i call the constructor in another file as shown:

 "/LoginScreen": (BuildContext context) => LoginScreen()

Those are the warnings it gives me:

warning: The parameter 'controller' is required. (missing_required_param at 
[gam3ity_aa] lib\main.dart:30)
warning: The parameter 'goToWelcomeListener' is required. 
(missing_required_param at [gam3ity_aa] lib\main.dart:30)
warning: The parameter 'goToWelcomeListener' is required. 
(missing_required_param at [gam3ity_aa] lib\screens\login\login_page.dart:34)
warning: The parameter 'controller' is required. (missing_required_param at 
[gam3ity_aa] lib\screens\login\login_page.dart:34)

What am i missing?


Solution 1: Nha Phạm Thị

Because of this! You marked that AnimationController and goToWelcomeListener are required params. But you just called LoginScreen() -> missing required params

LoginScreen(
 {@required AnimationController controller,
 @required this.goToWelcomeListener})
: this.enterAnimation = new LoginEnterAnimation(controller);