Index: pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
index 7b888c638f034111c2cf7622d4c10c6e9652259e..4f3bb2c64a47c432fe238d5f16f22d574dd71ee7 100644 |
--- a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
+++ b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
@@ -71,26 +71,19 @@ void addDefaultArgDetails( |
} |
} |
- //TODO(pq): generalize and unify with _getDefaultValue |
if (options?.generateFlutterWidgetChildrenBoilerPlate == true) { |
if (element is ConstructorElement) { |
- ConstructorElement constructorElement = element; |
- ClassElement classElement = constructorElement.enclosingElement; |
- if (isFlutterWidget(classElement)) { |
- for (ParameterElement param in constructorElement.parameters) { |
+ if (isFlutterWidget(element.enclosingElement)) { |
+ for (ParameterElement param in element.parameters) { |
if (param.name == 'children') { |
- DartType type = param.type; |
- if (type is InterfaceType && isDartList(type)) { |
- InterfaceType interfaceType = type; |
- List<DartType> typeArguments = interfaceType.typeArguments; |
- if (typeArguments.length == 1) { |
- if (sb.isNotEmpty) { |
- sb.write(', '); |
- } |
- offset = sb.length; |
- sb.write('children: <${typeArguments.first.name}>[]'); |
- } |
+ String defaultValue = getDefaultStringParameterValue(param); |
+ if (sb.isNotEmpty) { |
+ sb.write(', '); |
} |
+ sb.write('children: '); |
+ offset = sb.length; |
+ sb.write(defaultValue); |
+ ranges.addAll([offset, defaultValue.length]); |
} |
} |
} |
@@ -184,6 +177,23 @@ CompletionSuggestion createLocalSuggestion(SimpleIdentifier id, |
return suggestion; |
} |
+String getDefaultStringParameterValue(ParameterElement param) { |
+ DartType type = param.type; |
+ if (type is InterfaceType && isDartList(type)) { |
+ List<DartType> typeArguments = type.typeArguments; |
+ StringBuffer sb = new StringBuffer(); |
+ if (typeArguments.length == 1) { |
+ DartType typeArg = typeArguments.first; |
+ if (!typeArg.isDynamic) { |
+ sb.write('<${typeArg.name}>'); |
+ } |
+ sb.write('[]'); |
+ return sb.toString(); |
+ } |
+ } |
+ return null; |
+} |
+ |
bool isDartList(DartType type) { |
ClassElement element = type.element; |
if (element != null) { |