Dart null safety (#6696)

* Dart null-safety - prepare migration annotations in library files

* Dart null-safety - apply migration

* Dart null-safety - update flatc to generate valid code

* Dart null-safety - fix flatc generated code and adjust tests

* Dart null-safety - update example and the generated code in the tests folder

* Dart null safety - minor review changes

* Dart - apply `dartfmt -w .`
This commit is contained in:
Ivan Dlugos
2021-06-22 17:54:57 +02:00
committed by GitHub
parent 71d43f3be9
commit a6ee335574
23 changed files with 3352 additions and 2649 deletions

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_local_variable
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
library namespace_a.namespace_b;
@@ -12,20 +12,25 @@ class UnionInNestedNSTypeId {
const UnionInNestedNSTypeId._(this.value);
factory UnionInNestedNSTypeId.fromValue(int value) {
if (value == null) value = 0;
if (!values.containsKey(value)) {
final result = values[value];
if (result == null) {
throw new StateError('Invalid value $value for bit flag enum UnionInNestedNSTypeId');
}
return values[value];
return result;
}
static UnionInNestedNSTypeId? _createOrNull(int? value) =>
value == null ? null : UnionInNestedNSTypeId.fromValue(value);
static const int minValue = 0;
static const int maxValue = 1;
static bool containsValue(int value) => values.containsKey(value);
static const UnionInNestedNSTypeId NONE = const UnionInNestedNSTypeId._(0);
static const UnionInNestedNSTypeId TableInNestedNS = const UnionInNestedNSTypeId._(1);
static const Map<int,UnionInNestedNSTypeId> values = {0: NONE,1: TableInNestedNS,};
static const Map<int, UnionInNestedNSTypeId> values = {
0: NONE,
1: TableInNestedNS};
static const fb.Reader<UnionInNestedNSTypeId> reader = const _UnionInNestedNSTypeIdReader();
@@ -51,13 +56,16 @@ class EnumInNestedNS {
const EnumInNestedNS._(this.value);
factory EnumInNestedNS.fromValue(int value) {
if (value == null) value = 0;
if (!values.containsKey(value)) {
final result = values[value];
if (result == null) {
throw new StateError('Invalid value $value for bit flag enum EnumInNestedNS');
}
return values[value];
return result;
}
static EnumInNestedNS? _createOrNull(int? value) =>
value == null ? null : EnumInNestedNS.fromValue(value);
static const int minValue = 0;
static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value);
@@ -65,7 +73,10 @@ class EnumInNestedNS {
static const EnumInNestedNS A = const EnumInNestedNS._(0);
static const EnumInNestedNS B = const EnumInNestedNS._(1);
static const EnumInNestedNS C = const EnumInNestedNS._(2);
static const Map<int,EnumInNestedNS> values = {0: A,1: B,2: C,};
static const Map<int, EnumInNestedNS> values = {
0: A,
1: B,
2: C};
static const fb.Reader<EnumInNestedNS> reader = const _EnumInNestedNSReader();
@@ -108,7 +119,7 @@ class TableInNestedNS {
TableInNestedNST unpack() => TableInNestedNST(
foo: foo);
static int pack(fb.Builder fbBuilder, TableInNestedNST object) {
static int pack(fb.Builder fbBuilder, TableInNestedNST? object) {
if (object == null) return 0;
return object.pack(fbBuilder);
}
@@ -118,11 +129,9 @@ class TableInNestedNST {
int foo;
TableInNestedNST({
this.foo});
this.foo = 0});
int pack(fb.Builder fbBuilder) {
assert(fbBuilder != null);
fbBuilder.startTable();
fbBuilder.addInt32(0, foo);
return fbBuilder.endTable();
@@ -143,9 +152,7 @@ class _TableInNestedNSReader extends fb.TableReader<TableInNestedNS> {
}
class TableInNestedNSBuilder {
TableInNestedNSBuilder(this.fbBuilder) {
assert(fbBuilder != null);
}
TableInNestedNSBuilder(this.fbBuilder) {}
final fb.Builder fbBuilder;
@@ -153,7 +160,7 @@ class TableInNestedNSBuilder {
fbBuilder.startTable();
}
int addFoo(int foo) {
int addFoo(int? foo) {
fbBuilder.addInt32(0, foo);
return fbBuilder.offset;
}
@@ -164,19 +171,16 @@ class TableInNestedNSBuilder {
}
class TableInNestedNSObjectBuilder extends fb.ObjectBuilder {
final int _foo;
final int? _foo;
TableInNestedNSObjectBuilder({
int foo,
int? foo,
})
: _foo = foo;
/// Finish building, and store into the [fbBuilder].
@override
int finish(
fb.Builder fbBuilder) {
assert(fbBuilder != null);
int finish(fb.Builder fbBuilder) {
fbBuilder.startTable();
fbBuilder.addInt32(0, _foo);
return fbBuilder.endTable();
@@ -184,7 +188,7 @@ class TableInNestedNSObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list.
@override
Uint8List toBytes([String fileIdentifier]) {
Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder();
int offset = finish(fbBuilder);
return fbBuilder.finish(offset, fileIdentifier);
@@ -210,7 +214,7 @@ class StructInNestedNS {
a: a,
b: b);
static int pack(fb.Builder fbBuilder, StructInNestedNST object) {
static int pack(fb.Builder fbBuilder, StructInNestedNST? object) {
if (object == null) return 0;
return object.pack(fbBuilder);
}
@@ -221,12 +225,10 @@ class StructInNestedNST {
int b;
StructInNestedNST({
this.a,
this.b});
required this.a,
required this.b});
int pack(fb.Builder fbBuilder) {
assert(fbBuilder != null);
fbBuilder.putInt32(b);
fbBuilder.putInt32(a);
return fbBuilder.offset;
@@ -250,9 +252,7 @@ class _StructInNestedNSReader extends fb.StructReader<StructInNestedNS> {
}
class StructInNestedNSBuilder {
StructInNestedNSBuilder(this.fbBuilder) {
assert(fbBuilder != null);
}
StructInNestedNSBuilder(this.fbBuilder) {}
final fb.Builder fbBuilder;
@@ -269,18 +269,15 @@ class StructInNestedNSObjectBuilder extends fb.ObjectBuilder {
final int _b;
StructInNestedNSObjectBuilder({
int a,
int b,
required int a,
required int b,
})
: _a = a,
_b = b;
/// Finish building, and store into the [fbBuilder].
@override
int finish(
fb.Builder fbBuilder) {
assert(fbBuilder != null);
int finish(fb.Builder fbBuilder) {
fbBuilder.putInt32(_b);
fbBuilder.putInt32(_a);
return fbBuilder.offset;
@@ -288,7 +285,7 @@ class StructInNestedNSObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list.
@override
Uint8List toBytes([String fileIdentifier]) {
Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder();
int offset = finish(fbBuilder);
return fbBuilder.finish(offset, fileIdentifier);