Skip to content
Open
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

# 9.0.0

- Tighten some types that were missing and inferred as `dynamic`. In particular,
`updates` are now `void Function` instead of `Function`, and builder factories
are now `Object Function()` instead of `Function`.
- Use `dart_flutter_team_lints` instead of `pedantic`, fix lint violations.

# 8.11.0

- Use `build ^3.0.0`.
Expand Down
2 changes: 1 addition & 1 deletion benchmark/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:pedantic/analysis_options.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml
14 changes: 8 additions & 6 deletions benchmark/lib/benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import 'package:benchmark/node.dart';
import 'package:benchmark/simple_value.dart';
import 'node.dart';
import 'simple_value.dart';

void benchmark() {
benchmarkHashCode();
benchmarkNestedRebuilds();
}

void benchmarkHashCode() {
final value = SimpleValue((b) => b
..anInt = 0
..aString = 'zero');
final value = SimpleValue(
(b) => b
..anInt = 0
..aString = 'zero',
);
_benchmark('hashCode', () => value.hashCode);
}

Expand Down Expand Up @@ -42,7 +44,7 @@ void _buildNested(NodeBuilder nodeBuilder, int depth) {
}
}

void _benchmark(String name, Function() function) {
void _benchmark(String name, void Function() function) {
// Warm up.
for (var i = 0; i != 1000; ++i) {
function();
Expand Down
4 changes: 1 addition & 3 deletions benchmark/lib/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library node;

import 'package:built_value/built_value.dart';

part 'node.g.dart';
Expand All @@ -15,6 +13,6 @@ abstract class Node implements Built<Node, NodeBuilder> {

Node? get right;

factory Node([Function(NodeBuilder) updates]) = _$Node;
factory Node([void Function(NodeBuilder) updates]) = _$Node;
Node._();
}
5 changes: 2 additions & 3 deletions benchmark/lib/simple_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library simple_value;

import 'package:built_value/built_value.dart';

part 'simple_value.g.dart';
Expand All @@ -13,6 +11,7 @@ abstract class SimpleValue implements Built<SimpleValue, SimpleValueBuilder> {

String get aString;

factory SimpleValue([Function(SimpleValueBuilder) updates]) = _$SimpleValue;
factory SimpleValue([void Function(SimpleValueBuilder) updates]) =
_$SimpleValue;
SimpleValue._();
}
8 changes: 7 additions & 1 deletion benchmark/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ dependencies:
dev_dependencies:
build_runner: '>=1.0.0 <3.0.0'
built_value_generator: ^8.11.0
pedantic: ^1.4.0
dart_flutter_team_lints: ^3.5.2
quiver: '>=0.21.0 <4.0.0'
test: ^1.0.0

dependency_overrides:
built_value:
path: ../built_value
built_value_generator:
path: ../built_value_generator
6 changes: 5 additions & 1 deletion built_value/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include: package:pedantic/analysis_options.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
errors:
avoid_catching_errors: ignore
2 changes: 1 addition & 1 deletion built_value/lib/async_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import 'package:built_value/serializer.dart';
import 'serializer.dart';

/// Deserializer for `BuiltList` that runs asynchronously.
///
Expand Down
70 changes: 41 additions & 29 deletions built_value/lib/built_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class Built<V extends Built<V, B>, B extends Builder<V, B>> {
///
/// The implementation of this method will be generated for you by the
/// built_value generator.
V rebuild(Function(B) updates);
V rebuild(void Function(B) updates);

/// Converts the instance to a builder [B].
///
Expand All @@ -43,7 +43,7 @@ abstract class Builder<V extends Built<V, B>, B extends Builder<V, B>> {
/// Applies updates.
///
/// [updates] is a function that takes a builder [B].
void update(Function(B)? updates);
void update(void Function(B)? updates);

/// Builds.
///
Expand Down Expand Up @@ -117,15 +117,16 @@ class BuiltValue {
/// to serialize with `@BuiltValueField(serialize: true)`.
final bool defaultSerialize;

const BuiltValue(
{this.instantiable = true,
this.nestedBuilders = true,
this.autoCreateNestedBuilders = true,
this.comparableBuilders = false,
this.generateBuilderOnSetField = false,
this.wireName,
this.defaultCompare = true,
this.defaultSerialize = true});
const BuiltValue({
this.instantiable = true,
this.nestedBuilders = true,
this.autoCreateNestedBuilders = true,
this.comparableBuilders = false,
this.generateBuilderOnSetField = false,
this.wireName,
this.defaultCompare = true,
this.defaultSerialize = true,
});
}

/// Annotation that was used to mark nullable Built Value fields.
Expand Down Expand Up @@ -156,20 +157,23 @@ class BuiltValueField {
/// indicates the name is to be taken from the literal field name.
final String? wireName;

/// Whether the field overrides the `nestedBuilders` setting from the class. Defaults to `null` which
/// indicates the setting is to be taken from the `nestedBuilders` setting on the class.
/// Whether the field overrides the `nestedBuilders` setting from the class.
/// Defaults to `null` which indicates the setting is to be taken from the
/// `nestedBuilders` setting on the class.
final bool? nestedBuilder;

/// Whether the field overrides the `autoCreateNestedBuilders` setting from the class. Defaults to `null` which
/// indicates the setting is to be taken from the `autoCreateNestedBuilders` setting on the class.
/// Whether the field overrides the `autoCreateNestedBuilders` setting from
/// the class. Defaults to `null` which indicates the setting is to be taken
/// from the `autoCreateNestedBuilders` setting on the class.
final bool? autoCreateNestedBuilder;

const BuiltValueField(
{this.compare,
this.serialize,
this.wireName,
this.nestedBuilder,
this.autoCreateNestedBuilder});
const BuiltValueField({
this.compare,
this.serialize,
this.wireName,
this.nestedBuilder,
this.autoCreateNestedBuilder,
});
}

/// Optionally, annotate a Built Value `Serializer` getters with this to
Expand All @@ -187,8 +191,10 @@ class BuiltValueSerializer {

final bool serializeNulls;

const BuiltValueSerializer(
{this.custom = false, this.serializeNulls = false});
const BuiltValueSerializer({
this.custom = false,
this.serializeNulls = false,
});
}

/// Memoized annotation for Built Value getters.
Expand Down Expand Up @@ -235,8 +241,11 @@ class BuiltValueEnumConst {
/// the fallback, if available, rather than throwing an exception.
final bool fallback;

const BuiltValueEnumConst(
{this.wireName, this.wireNumber, this.fallback = false});
const BuiltValueEnumConst({
this.wireName,
this.wireNumber,
this.fallback = false,
});
}

/// Optionally, annotate methods with this to cause them to be called by
Expand Down Expand Up @@ -275,8 +284,10 @@ class BuiltValueHook {
/// ```
final bool finalizeBuilder;

const BuiltValueHook(
{this.initializeBuilder = false, this.finalizeBuilder = false});
const BuiltValueHook({
this.initializeBuilder = false,
this.finalizeBuilder = false,
});
}

/// Enum Class base class.
Expand Down Expand Up @@ -319,7 +330,7 @@ typedef BuiltValueToStringHelperProvider = BuiltValueToStringHelper Function(
/// are [IndentingBuiltValueToStringHelper], which is the default, and
/// [FlatBuiltValueToStringHelper].
BuiltValueToStringHelperProvider newBuiltValueToStringHelper =
(String className) => IndentingBuiltValueToStringHelper(className);
IndentingBuiltValueToStringHelper.new;

/// Interface for built_value toString() output helpers.
///
Expand Down Expand Up @@ -422,7 +433,8 @@ class BuiltValueNullFieldError extends Error {

@override
String toString() =>
'Tried to construct class "$type" with null for non-nullable field "$field".';
'Tried to construct class "$type" with null for non-nullable field '
'"$field".';
}

/// [Error] indicating that a built_value class constructor was called with
Expand Down
2 changes: 1 addition & 1 deletion built_value/lib/iso_8601_date_time_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'serializer.dart';

/// Alternative serializer for [DateTime].
///
Expand Down
2 changes: 1 addition & 1 deletion built_value/lib/iso_8601_duration_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'serializer.dart';

/// Alternative serializer for [Duration].
///
Expand Down
Loading