Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map from optional arguments #1905

Open
duzenko opened this issue Oct 13, 2021 · 1 comment
Open

Map from optional arguments #1905

duzenko opened this issue Oct 13, 2021 · 1 comment
Labels
feature Proposed language feature that solves one or more problems

Comments

@duzenko
Copy link

duzenko commented Oct 13, 2021

It's tedious to manually construct Map instances for JSON serialization from primitive types. Would be great to have some syntax sugar like this

void callApi({
  String? a,
  String? b,
  String? c,
}) {
  final params = <String, dynamic>{
    'a': a,
    'b': b,
    'c': c,
  };
  print(params);
}

void callApi_proposal({
  String? a,
  String? b,
  String? c,
}) {
  print($optionals); // $optionals is all optional parameters as a Map<String, dynamic>
}
@duzenko duzenko added the feature Proposed language feature that solves one or more problems label Oct 13, 2021
@ykmnkmi
Copy link

ykmnkmi commented Oct 13, 2021

my suggestion:

void call({String? a, String? b, Map<String, Object?> **params}) {
  print({'a': a, 'b': b, ...params});
}

also same for positional:

void call(String value, [List<String> *params]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants