Fix const bug2

This commit is contained in:
Tobe O 2018-06-27 01:51:21 -04:00
parent dfb4957bf7
commit 7768b906b7
5 changed files with 13 additions and 2 deletions

View file

@ -1,3 +1,7 @@
# 2.0.8+2
* Better discern when custom methods disqualify classes
from `const` protection.
# 2.0.8+1 # 2.0.8+1
* Fix generation of `const` constructors with iterables. * Fix generation of `const` constructors with iterables.

View file

@ -68,7 +68,8 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
bool shouldBeConstant(BuildContext ctx) { bool shouldBeConstant(BuildContext ctx) {
// Check if all fields are without a getter // Check if all fields are without a getter
return !isAssignableToModel(ctx.clazz.type) && return !isAssignableToModel(ctx.clazz.type) &&
ctx.clazz.fields.every((f) => f.getter == null || f.setter == null); ctx.clazz.fields.every((f) =>
f.getter?.isAbstract != false && f.setter?.isAbstract != false);
} }
/// Generate a constructor with named parameters. /// Generate a constructor with named parameters.

View file

@ -1,5 +1,5 @@
name: angel_serialize_generator name: angel_serialize_generator
version: 2.0.8+1 version: 2.0.8+2
description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling. description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/serialize homepage: https://github.com/angel-dart/serialize

View file

@ -91,6 +91,10 @@ main() {
expect(library.copyWith(), library); expect(library.copyWith(), library);
}); });
test('custom method', () {
expect(jkRowling.customMethod, 'hey!');
});
test('required fields fromMap', () { test('required fields fromMap', () {
expect(() => AuthorSerializer.fromMap({}), throwsFormatException); expect(() => AuthorSerializer.fromMap({}), throwsFormatException);
}); });

View file

@ -15,6 +15,8 @@ abstract class _Author extends Model {
@required @required
String get name; String get name;
String get customMethod => 'hey!';
@Required('Custom message for missing `age`') @Required('Custom message for missing `age`')
int get age; int get age;