error: The argument type '() → Null' can't be assigned to the parameter type '(Null) → FutureOr'












0















    import 'package:flutter/material.dart';
import 'package:camera/camera.dart';


class Register extends StatefulWidget{
List<CameraDescription> cameras;
@override
_Register createState() {
return _Register();
}

Register(this.cameras);
}

class _Register extends State<Register>{

CameraController controller;

@override
Widget build(BuildContext context){
return MaterialApp(
title: 'Registration Certificate',
home: Scaffold(
appBar: AppBar(
title: new Text('Register'),
),

body: Container()
),
);
}


@override
void initState(){
super.initState();
controller = new CameraController(widget.cameras[0], ResolutionPreset.medium);
//**SYNTAX ERROR from the below code**
controller.initialize().then(() {});
}
}


ERROR DETAILS




error: The argument type '() → Null' can't be assigned to the parameter type '(Null) → FutureOr'. (argument_type_not_assignable at [fluttercam] libpacksreg.certificate.dart:38)




When I use '_' underscore the code is working fine, Error resolved!



controller.initialize().then((_) {});


Can anyone explain what is going on behind the scenes?










share|improve this question





























    0















        import 'package:flutter/material.dart';
    import 'package:camera/camera.dart';


    class Register extends StatefulWidget{
    List<CameraDescription> cameras;
    @override
    _Register createState() {
    return _Register();
    }

    Register(this.cameras);
    }

    class _Register extends State<Register>{

    CameraController controller;

    @override
    Widget build(BuildContext context){
    return MaterialApp(
    title: 'Registration Certificate',
    home: Scaffold(
    appBar: AppBar(
    title: new Text('Register'),
    ),

    body: Container()
    ),
    );
    }


    @override
    void initState(){
    super.initState();
    controller = new CameraController(widget.cameras[0], ResolutionPreset.medium);
    //**SYNTAX ERROR from the below code**
    controller.initialize().then(() {});
    }
    }


    ERROR DETAILS




    error: The argument type '() → Null' can't be assigned to the parameter type '(Null) → FutureOr'. (argument_type_not_assignable at [fluttercam] libpacksreg.certificate.dart:38)




    When I use '_' underscore the code is working fine, Error resolved!



    controller.initialize().then((_) {});


    Can anyone explain what is going on behind the scenes?










    share|improve this question



























      0












      0








      0








          import 'package:flutter/material.dart';
      import 'package:camera/camera.dart';


      class Register extends StatefulWidget{
      List<CameraDescription> cameras;
      @override
      _Register createState() {
      return _Register();
      }

      Register(this.cameras);
      }

      class _Register extends State<Register>{

      CameraController controller;

      @override
      Widget build(BuildContext context){
      return MaterialApp(
      title: 'Registration Certificate',
      home: Scaffold(
      appBar: AppBar(
      title: new Text('Register'),
      ),

      body: Container()
      ),
      );
      }


      @override
      void initState(){
      super.initState();
      controller = new CameraController(widget.cameras[0], ResolutionPreset.medium);
      //**SYNTAX ERROR from the below code**
      controller.initialize().then(() {});
      }
      }


      ERROR DETAILS




      error: The argument type '() → Null' can't be assigned to the parameter type '(Null) → FutureOr'. (argument_type_not_assignable at [fluttercam] libpacksreg.certificate.dart:38)




      When I use '_' underscore the code is working fine, Error resolved!



      controller.initialize().then((_) {});


      Can anyone explain what is going on behind the scenes?










      share|improve this question
















          import 'package:flutter/material.dart';
      import 'package:camera/camera.dart';


      class Register extends StatefulWidget{
      List<CameraDescription> cameras;
      @override
      _Register createState() {
      return _Register();
      }

      Register(this.cameras);
      }

      class _Register extends State<Register>{

      CameraController controller;

      @override
      Widget build(BuildContext context){
      return MaterialApp(
      title: 'Registration Certificate',
      home: Scaffold(
      appBar: AppBar(
      title: new Text('Register'),
      ),

      body: Container()
      ),
      );
      }


      @override
      void initState(){
      super.initState();
      controller = new CameraController(widget.cameras[0], ResolutionPreset.medium);
      //**SYNTAX ERROR from the below code**
      controller.initialize().then(() {});
      }
      }


      ERROR DETAILS




      error: The argument type '() → Null' can't be assigned to the parameter type '(Null) → FutureOr'. (argument_type_not_assignable at [fluttercam] libpacksreg.certificate.dart:38)




      When I use '_' underscore the code is working fine, Error resolved!



      controller.initialize().then((_) {});


      Can anyone explain what is going on behind the scenes?







      dart flutter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 26 '18 at 6:30









      Günter Zöchbauer

      322k69958895




      322k69958895










      asked Nov 26 '18 at 6:25









      RajathRajath

      8410




      8410
























          1 Answer
          1






          active

          oldest

          votes


















          0














          When a function that takes a parameter is expected,



          (Null) → FutureOr<dynamic>


          you can't pass a function that accepts none



          () → Null


          _ is a valid parameter name and is by convention used to indicate that the parameter is not used and makes the passed function compatible with the defined parameter type because it now accepts a parameter.



          controller.initialize() returns a Future and the then(...) method expects a function that it calls when the async task is completed and the result of the completed async task is passed as a parameter to that callback function.



          https://api.dartlang.org/stable/2.1.0/dart-async/Future/then.html shows the parameter definition for then:



          FutureOr<R> onValue(T value)


          which is a function that accepts a parameter of the generic type T and returns a value of FutureOr<R>






          share|improve this answer


























          • Thanks for your quick response @Günter Zöchbauer, Can you please explain what is the use of it?

            – Rajath
            Nov 26 '18 at 6:41













          • The use of what? I thought I explained what Future.then is for. You pass a function that Future calls when the async task is completed. dartlang.org/tutorials/language/futures might help.

            – Günter Zöchbauer
            Nov 26 '18 at 6:42













          • I mean the parameter we are passing. for example '_' underscore

            – Rajath
            Nov 26 '18 at 6:44











          • Many thanks for your warm response @Günter Zöchbauer

            – Rajath
            Nov 26 '18 at 6:49











          • There is nothing about it. You can change it to foo and it will do the same.

            – Günter Zöchbauer
            Nov 26 '18 at 6:49











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475734%2ferror-the-argument-type-%25e2%2586%2592-null-cant-be-assigned-to-the-parameter-type-n%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          When a function that takes a parameter is expected,



          (Null) → FutureOr<dynamic>


          you can't pass a function that accepts none



          () → Null


          _ is a valid parameter name and is by convention used to indicate that the parameter is not used and makes the passed function compatible with the defined parameter type because it now accepts a parameter.



          controller.initialize() returns a Future and the then(...) method expects a function that it calls when the async task is completed and the result of the completed async task is passed as a parameter to that callback function.



          https://api.dartlang.org/stable/2.1.0/dart-async/Future/then.html shows the parameter definition for then:



          FutureOr<R> onValue(T value)


          which is a function that accepts a parameter of the generic type T and returns a value of FutureOr<R>






          share|improve this answer


























          • Thanks for your quick response @Günter Zöchbauer, Can you please explain what is the use of it?

            – Rajath
            Nov 26 '18 at 6:41













          • The use of what? I thought I explained what Future.then is for. You pass a function that Future calls when the async task is completed. dartlang.org/tutorials/language/futures might help.

            – Günter Zöchbauer
            Nov 26 '18 at 6:42













          • I mean the parameter we are passing. for example '_' underscore

            – Rajath
            Nov 26 '18 at 6:44











          • Many thanks for your warm response @Günter Zöchbauer

            – Rajath
            Nov 26 '18 at 6:49











          • There is nothing about it. You can change it to foo and it will do the same.

            – Günter Zöchbauer
            Nov 26 '18 at 6:49
















          0














          When a function that takes a parameter is expected,



          (Null) → FutureOr<dynamic>


          you can't pass a function that accepts none



          () → Null


          _ is a valid parameter name and is by convention used to indicate that the parameter is not used and makes the passed function compatible with the defined parameter type because it now accepts a parameter.



          controller.initialize() returns a Future and the then(...) method expects a function that it calls when the async task is completed and the result of the completed async task is passed as a parameter to that callback function.



          https://api.dartlang.org/stable/2.1.0/dart-async/Future/then.html shows the parameter definition for then:



          FutureOr<R> onValue(T value)


          which is a function that accepts a parameter of the generic type T and returns a value of FutureOr<R>






          share|improve this answer


























          • Thanks for your quick response @Günter Zöchbauer, Can you please explain what is the use of it?

            – Rajath
            Nov 26 '18 at 6:41













          • The use of what? I thought I explained what Future.then is for. You pass a function that Future calls when the async task is completed. dartlang.org/tutorials/language/futures might help.

            – Günter Zöchbauer
            Nov 26 '18 at 6:42













          • I mean the parameter we are passing. for example '_' underscore

            – Rajath
            Nov 26 '18 at 6:44











          • Many thanks for your warm response @Günter Zöchbauer

            – Rajath
            Nov 26 '18 at 6:49











          • There is nothing about it. You can change it to foo and it will do the same.

            – Günter Zöchbauer
            Nov 26 '18 at 6:49














          0












          0








          0







          When a function that takes a parameter is expected,



          (Null) → FutureOr<dynamic>


          you can't pass a function that accepts none



          () → Null


          _ is a valid parameter name and is by convention used to indicate that the parameter is not used and makes the passed function compatible with the defined parameter type because it now accepts a parameter.



          controller.initialize() returns a Future and the then(...) method expects a function that it calls when the async task is completed and the result of the completed async task is passed as a parameter to that callback function.



          https://api.dartlang.org/stable/2.1.0/dart-async/Future/then.html shows the parameter definition for then:



          FutureOr<R> onValue(T value)


          which is a function that accepts a parameter of the generic type T and returns a value of FutureOr<R>






          share|improve this answer















          When a function that takes a parameter is expected,



          (Null) → FutureOr<dynamic>


          you can't pass a function that accepts none



          () → Null


          _ is a valid parameter name and is by convention used to indicate that the parameter is not used and makes the passed function compatible with the defined parameter type because it now accepts a parameter.



          controller.initialize() returns a Future and the then(...) method expects a function that it calls when the async task is completed and the result of the completed async task is passed as a parameter to that callback function.



          https://api.dartlang.org/stable/2.1.0/dart-async/Future/then.html shows the parameter definition for then:



          FutureOr<R> onValue(T value)


          which is a function that accepts a parameter of the generic type T and returns a value of FutureOr<R>







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 6:34

























          answered Nov 26 '18 at 6:28









          Günter ZöchbauerGünter Zöchbauer

          322k69958895




          322k69958895













          • Thanks for your quick response @Günter Zöchbauer, Can you please explain what is the use of it?

            – Rajath
            Nov 26 '18 at 6:41













          • The use of what? I thought I explained what Future.then is for. You pass a function that Future calls when the async task is completed. dartlang.org/tutorials/language/futures might help.

            – Günter Zöchbauer
            Nov 26 '18 at 6:42













          • I mean the parameter we are passing. for example '_' underscore

            – Rajath
            Nov 26 '18 at 6:44











          • Many thanks for your warm response @Günter Zöchbauer

            – Rajath
            Nov 26 '18 at 6:49











          • There is nothing about it. You can change it to foo and it will do the same.

            – Günter Zöchbauer
            Nov 26 '18 at 6:49



















          • Thanks for your quick response @Günter Zöchbauer, Can you please explain what is the use of it?

            – Rajath
            Nov 26 '18 at 6:41













          • The use of what? I thought I explained what Future.then is for. You pass a function that Future calls when the async task is completed. dartlang.org/tutorials/language/futures might help.

            – Günter Zöchbauer
            Nov 26 '18 at 6:42













          • I mean the parameter we are passing. for example '_' underscore

            – Rajath
            Nov 26 '18 at 6:44











          • Many thanks for your warm response @Günter Zöchbauer

            – Rajath
            Nov 26 '18 at 6:49











          • There is nothing about it. You can change it to foo and it will do the same.

            – Günter Zöchbauer
            Nov 26 '18 at 6:49

















          Thanks for your quick response @Günter Zöchbauer, Can you please explain what is the use of it?

          – Rajath
          Nov 26 '18 at 6:41







          Thanks for your quick response @Günter Zöchbauer, Can you please explain what is the use of it?

          – Rajath
          Nov 26 '18 at 6:41















          The use of what? I thought I explained what Future.then is for. You pass a function that Future calls when the async task is completed. dartlang.org/tutorials/language/futures might help.

          – Günter Zöchbauer
          Nov 26 '18 at 6:42







          The use of what? I thought I explained what Future.then is for. You pass a function that Future calls when the async task is completed. dartlang.org/tutorials/language/futures might help.

          – Günter Zöchbauer
          Nov 26 '18 at 6:42















          I mean the parameter we are passing. for example '_' underscore

          – Rajath
          Nov 26 '18 at 6:44





          I mean the parameter we are passing. for example '_' underscore

          – Rajath
          Nov 26 '18 at 6:44













          Many thanks for your warm response @Günter Zöchbauer

          – Rajath
          Nov 26 '18 at 6:49





          Many thanks for your warm response @Günter Zöchbauer

          – Rajath
          Nov 26 '18 at 6:49













          There is nothing about it. You can change it to foo and it will do the same.

          – Günter Zöchbauer
          Nov 26 '18 at 6:49





          There is nothing about it. You can change it to foo and it will do the same.

          – Günter Zöchbauer
          Nov 26 '18 at 6:49


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475734%2ferror-the-argument-type-%25e2%2586%2592-null-cant-be-assigned-to-the-parameter-type-n%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Unable to find Lightning Node

          Futebolista