passsy / dart-lint

An opinionated, community-driven set of lint rules for Dart and Flutter projects. Like pedantic but stricter
Apache License 2.0
277 stars 82 forks source link

The argument type 'Function' can't be assigned to the parameter type 'void Function() #18

Closed Jean-Alves closed 4 years ago

Jean-Alves commented 4 years ago

I have 1 problem with lint and mobx

in the raisedbutton onprees I put the mobx computer and the following error comes out

The argument type 'Function' can't be assigned to the parameter type 'void Function ()'

code example

// Page
final LoginController controller = LoginModule.to.get <LoginController> ();
Observer (
  builder: (_) {
    return Container (
      height: 50,
      child: RaisedButton (
      onPressed: controller.loginPressed,
      shape: RoundedRectangleBorder (
        borderRadius: BorderRadius.circular (20),
      ),
      child: controller.loading
        ? const CircularProgressIndicator (
          valueColor:
            AlwaysStoppedAnimation (Colors.white),
          )
        : const Text (
            'Log in',
            style: TextStyle (
              color: Colors.white,
              fontSize: 20,
            ),
          ),
      ),
    );
  },
)
// Controller
@computed
Function get loginPressed =>
    emailValid && passwordValid &&! loading? _login: null;
passsy commented 4 years ago

Can't you change the loginPressed function to match the type? The return type of your function is dynamic not void

@computed
-Function get loginPressed =>
+void Function() get loginPressed =>
    emailValid && passwordValid &&! loading? _login: null;
Jean-Alves commented 4 years ago

Worked, thank you