Reputation: 417
When constructing a class/widget, usually there are some properties that are required and some that are optional (using @required decorator in the class constructor).
It would be nice if vs code automatically fill in the required keys (eg. child:, onTap:) of these properties instead of just telling an error that "The parameter 'requiredParameter' is required.dart(missing_required_param)".
For example
//example of the class with constructors that we want to use
class Product {
final String id;
final String title;
final String description;
double price;
String imageUrl;
bool isFavorite;
Product({
@required this.id,
@required this.title,
@required this.description,
this.price,
this.imageUrl,
this.isFavorite = false,
});
}
//desired behavior of autocomplete / shortcut
Product(
id: ,
title: ,
description: ,
)
Currently, what I do is I manually add the required parameter from the class documentation / vscode popup instructions (eg:
The parameter 'price' is required.dart(missing_required_param)
The parameter 'id' is required.dart(missing_required_param)
The parameter 'title' is required.dart(missing_required_param)
)
Upvotes: 6
Views: 3194
Reputation: 13890
If you are using VSCode, install Dart Data Class Generator
Upvotes: 3
Reputation: 143
Open VS Code settings.json
and add the following:
"dart.previewNewCompletionPlaceholders": true
EDIT 2020-01-21:
Thanks William Terrill for your comment mentioning this, this feature is no longer in preview and can be activated with the following command:
"dart.insertArgumentPlaceholders": true
Upvotes: 4