Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 8.12.8

- Support generating from classes using primary constructors.

# 8.12.7

- Allow `analyzer 13.0.0` and `analyzer 14.0.0`
Expand Down Expand Up @@ -200,7 +204,7 @@

# 8.3.1

- Fix generation support for optional generic bounds, e.g.
- Fix generation support for optional generic bounds, e.g.
`class Foo<T extends Object?>`.
- Fix generation for classes with names starting `$`.
- Ignore lint `unnecessary_lambdas` in generated code.
Expand Down
11 changes: 7 additions & 4 deletions built_value_generator/lib/src/value_source_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,11 @@ abstract class ValueSourceClass
}

final expectedConstructor = '$name._()';
bool constructorCheck(ConstructorDeclaration c) {
final check = c.typeName != null ? expectedConstructor : '_()';
return c.toSource().contains(check);
}

if (valueClassConstructors.isEmpty) {
result.add(
GeneratorError(
Expand All @@ -683,7 +688,7 @@ abstract class ValueSourceClass
} else if (valueClassConstructors.length > 1) {
var found = false;
for (var constructor in valueClassConstructors) {
if (constructor.toSource().contains(expectedConstructor)) {
if (constructorCheck(constructor)) {
found = true;
} else {
result.add(
Expand All @@ -709,9 +714,7 @@ abstract class ValueSourceClass
),
);
}
} else if (!(valueClassConstructors.single.toSource().contains(
expectedConstructor,
))) {
} else if (!constructorCheck(valueClassConstructors.single)) {
result.add(
GeneratorError(
(b) => b
Expand Down