I am opening a modal dialog in Flutter and wish to pass in a single parameter (postId) to the modal for further processing. But this is generating an error as shown.
class SharingDialog extends StatefulWidget {
@override
final String postId; // <--- generates the error, "Field doesn't override an inherited getter or setter"
SharingDialog({
String postId
}): this.postId = postId;
SharingDialogState createState() => new SharingDialogState(postId);
}
class SharingDialogState extends State<SharingDialog> {
SharingDialogState(this.postId);
final String postId;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar:
child: AppBar(
title: const Text('Share this Post'),
actions: [
new FlatButton(
onPressed: () {
print("Sharing Post ID: " + this.postId);
},
child: new Text('SHARE)
),
],
),
),
body: new Text("SHARING SCREEN"),
);
}
And then there is a click to open the modal using the following code which generates the accompanying error:
Code:
return new SharingDialog(postId);
Error: Too many positional arguments: 0 allowed, but 1 found.
How do you pass parameter(s) if not this way?
First:
Remove override keyword above postId
@override <-- this one
final String postId;
Second:
Because you are using named parameter , send the param like this way:
return new SharingDialog(postId: postId);
If you want more information about Optional named parameters, check this link:
https://www.dartlang.org/guides/language/language-tour#optional-parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With