error: The argument type '() → Null' can't be assigned to the parameter type '(Null) → FutureOr'
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
add a comment |
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
add a comment |
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
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
dart
edited Nov 26 '18 at 6:30
Günter Zöchbauer
322k69958895
322k69958895
asked Nov 26 '18 at 6:25
RajathRajath
8410
8410
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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>
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 whatFuture.thenis for. You pass a function thatFuturecalls 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 tofooand it will do the same.
– Günter Zöchbauer
Nov 26 '18 at 6:49
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
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 whatFuture.thenis for. You pass a function thatFuturecalls 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 tofooand it will do the same.
– Günter Zöchbauer
Nov 26 '18 at 6:49
add a comment |
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>
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 whatFuture.thenis for. You pass a function thatFuturecalls 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 tofooand it will do the same.
– Günter Zöchbauer
Nov 26 '18 at 6:49
add a comment |
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>
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>
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 whatFuture.thenis for. You pass a function thatFuturecalls 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 tofooand it will do the same.
– Günter Zöchbauer
Nov 26 '18 at 6:49
add a comment |
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 whatFuture.thenis for. You pass a function thatFuturecalls 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 tofooand 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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