Skip to content

Commit f9b9106

Browse files
committed
Replaces isNullable with isOptional.
Signed-off-by: Chito <[email protected]>
1 parent f6eb0d6 commit f9b9106

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

protoc_plugin/lib/src/message_generator.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ class MessageGenerator extends ProtobufContainer {
554554
out.println(commentBlock);
555555
}
556556

557-
if (useNullable && field.isNullable) {
557+
if (useNullable && field.isOptional) {
558558
fieldTypeString += '?';
559559
}
560560

@@ -567,7 +567,7 @@ class MessageGenerator extends ProtobufContainer {
567567
defaultExpr,
568568
field.isRepeated,
569569
field.isMapField,
570-
useNullable && field.isNullable);
570+
useNullable && field.isOptional);
571571

572572
out.printlnAnnotated(
573573
'$fieldTypeString get ${names!.fieldName} => $getterExpr;', [
@@ -596,7 +596,7 @@ class MessageGenerator extends ProtobufContainer {
596596
_emitOverrideIf(field.overridesSetter, out);
597597
_emitIndexAnnotation(field.number, out);
598598
if (fastSetter != null) {
599-
if (useNullable && field.isNullable) {
599+
if (useNullable && field.isOptional) {
600600
fastSetter += 'Nullable';
601601
}
602602
out.printlnAnnotated(
@@ -612,7 +612,7 @@ class MessageGenerator extends ProtobufContainer {
612612
]);
613613
} else {
614614
final setterName =
615-
useNullable && field.isNullable ? '\$_setFieldNullable' : '\$_setField';
615+
useNullable && field.isOptional ? '\$_setFieldNullable' : '\$_setField';
616616

617617
out.printlnAnnotated(
618618
'set ${names.fieldName}'

protoc_plugin/lib/src/protobuf_field.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ class ProtobufField {
6565
bool get isRepeated =>
6666
descriptor.label == FieldDescriptorProto_Label.LABEL_REPEATED;
6767

68+
bool get isOptional {
69+
if (isRepeated) return false;
70+
if (isRequired || !descriptor.proto3Optional) return false;
71+
return true;
72+
}
73+
6874
/// Whether a numeric field is repeated and must be encoded with packed
6975
/// encoding.
7076
///
@@ -140,12 +146,6 @@ class ProtobufField {
140146
// for example in package:protobuf/src/protobuf/mixins/well_known.dart.
141147
}
142148

143-
bool get isNullable {
144-
if (isRepeated) return false;
145-
if (isRequired) return false;
146-
return descriptor.proto3Optional || baseType.isMessage;
147-
}
148-
149149
/// Returns the expression to use for the Dart type.
150150
String getDartType() {
151151
if (isMapField) {

0 commit comments

Comments
 (0)