@@ -248,7 +248,7 @@ class PostgresBinaryEncoder {
248248 );
249249 }
250250 throw FormatException (
251- 'Invalid type for parameter value. Expected: List<String> Got: ${input .runtimeType }' );
251+ 'Invalid type for parameter value. Expected: List<String? > Got: ${input .runtimeType }' );
252252 }
253253
254254 case TypeOid .point:
@@ -358,7 +358,7 @@ class PostgresBinaryEncoder {
358358 );
359359 }
360360 throw FormatException (
361- 'Invalid type for parameter value. Expected: List<bool> Got: ${input .runtimeType }' );
361+ 'Invalid type for parameter value. Expected: List<bool? > Got: ${input .runtimeType }' );
362362 }
363363
364364 case TypeOid .smallIntegerArray:
@@ -373,7 +373,7 @@ class PostgresBinaryEncoder {
373373 );
374374 }
375375 throw FormatException (
376- 'Invalid type for parameter value. Expected: List<int> Got: ${input .runtimeType }' );
376+ 'Invalid type for parameter value. Expected: List<int? > Got: ${input .runtimeType }' );
377377 }
378378
379379 case TypeOid .integerArray:
@@ -388,7 +388,7 @@ class PostgresBinaryEncoder {
388388 );
389389 }
390390 throw FormatException (
391- 'Invalid type for parameter value. Expected: List<int> Got: ${input .runtimeType }' );
391+ 'Invalid type for parameter value. Expected: List<int? > Got: ${input .runtimeType }' );
392392 }
393393
394394 case TypeOid .bigIntegerArray:
@@ -403,7 +403,7 @@ class PostgresBinaryEncoder {
403403 );
404404 }
405405 throw FormatException (
406- 'Invalid type for parameter value. Expected: List<int> Got: ${input .runtimeType }' );
406+ 'Invalid type for parameter value. Expected: List<int? > Got: ${input .runtimeType }' );
407407 }
408408
409409 case TypeOid .dateArray:
@@ -419,7 +419,7 @@ class PostgresBinaryEncoder {
419419 );
420420 }
421421 throw FormatException (
422- 'Invalid type for parameter value. Expected: List<DateTime> Got: ${input .runtimeType }' );
422+ 'Invalid type for parameter value. Expected: List<DateTime? > Got: ${input .runtimeType }' );
423423 }
424424
425425 case TypeOid .timeArray:
@@ -434,7 +434,7 @@ class PostgresBinaryEncoder {
434434 );
435435 }
436436 throw FormatException (
437- 'Invalid type for parameter value. Expected: List<Time> Got: ${input .runtimeType }' );
437+ 'Invalid type for parameter value. Expected: List<Time? > Got: ${input .runtimeType }' );
438438 }
439439
440440 case TypeOid .timestampArray:
@@ -450,7 +450,7 @@ class PostgresBinaryEncoder {
450450 );
451451 }
452452 throw FormatException (
453- 'Invalid type for parameter value. Expected: List<DateTime> Got: ${input .runtimeType }' );
453+ 'Invalid type for parameter value. Expected: List<DateTime? > Got: ${input .runtimeType }' );
454454 }
455455
456456 case TypeOid .timestampTzArray:
@@ -466,14 +466,15 @@ class PostgresBinaryEncoder {
466466 );
467467 }
468468 throw FormatException (
469- 'Invalid type for parameter value. Expected: List<DateTime> Got: ${input .runtimeType }' );
469+ 'Invalid type for parameter value. Expected: List<DateTime? > Got: ${input .runtimeType }' );
470470 }
471471
472472 case TypeOid .varCharArray:
473473 {
474474 if (input is List ) {
475- final bytesArray =
476- _castOrThrowList <String >(input).map ((v) => encoding.encode (v));
475+ final bytesArray = _castOrThrowList <String >(input)
476+ .map ((v) => v == null ? null : encoding.encode (v))
477+ .toList ();
477478 return _writeListBytes <List <int >>(
478479 bytesArray,
479480 1043 ,
@@ -483,14 +484,15 @@ class PostgresBinaryEncoder {
483484 );
484485 }
485486 throw FormatException (
486- 'Invalid type for parameter value. Expected: List<String> Got: ${input .runtimeType }' );
487+ 'Invalid type for parameter value. Expected: List<String? > Got: ${input .runtimeType }' );
487488 }
488489
489490 case TypeOid .textArray:
490491 {
491492 if (input is List ) {
492- final bytesArray =
493- _castOrThrowList <String >(input).map ((v) => encoding.encode (v));
493+ final bytesArray = _castOrThrowList <String >(input)
494+ .map ((v) => v == null ? null : encoding.encode (v))
495+ .toList ();
494496 return _writeListBytes <List <int >>(
495497 bytesArray,
496498 25 ,
@@ -500,7 +502,7 @@ class PostgresBinaryEncoder {
500502 );
501503 }
502504 throw FormatException (
503- 'Invalid type for parameter value. Expected: List<String> Got: ${input .runtimeType }' );
505+ 'Invalid type for parameter value. Expected: List<String? > Got: ${input .runtimeType }' );
504506 }
505507
506508 case TypeOid .doubleArray:
@@ -515,13 +517,14 @@ class PostgresBinaryEncoder {
515517 );
516518 }
517519 throw FormatException (
518- 'Invalid type for parameter value. Expected: List<double> Got: ${input .runtimeType }' );
520+ 'Invalid type for parameter value. Expected: List<double? > Got: ${input .runtimeType }' );
519521 }
520522
521523 case TypeOid .jsonbArray:
522524 {
523525 if (input is List ) {
524- final objectsArray = input.map (_jsonFusedEncoding (encoding).encode);
526+ final objectsArray =
527+ input.map (_jsonFusedEncoding (encoding).encode).toList ();
525528 return _writeListBytes <List <int >>(
526529 objectsArray,
527530 3802 ,
@@ -581,19 +584,19 @@ class PostgresBinaryEncoder {
581584 throw ArgumentError ('Cannot encode `$input ` into oid($_typeOid ).' );
582585 }
583586
584- List <V > _castOrThrowList <V >(List input) {
585- if (input is List <V >) {
587+ List <V ? > _castOrThrowList <V >(List input) {
588+ if (input is List <V ? >) {
586589 return input;
587590 }
588- if (input.any ((e) => e is ! V )) {
591+ if (input.any ((e) => e is ! V ? )) {
589592 throw FormatException (
590- 'Invalid type for parameter value. Expected: List<${V .runtimeType }> Got: ${input .runtimeType }' );
593+ 'Invalid type for parameter value. Expected: List<${V .runtimeType }? > Got: ${input .runtimeType }' );
591594 }
592- return input.cast <V >();
595+ return input.cast <V ? >();
593596 }
594597
595598 Uint8List _writeListBytes <V >(
596- Iterable < V > value,
599+ List < V ? > value,
597600 int type,
598601 int Function (V item) lengthEncoder,
599602 void Function (PgByteDataWriter writer, V item) valueEncoder,
@@ -608,6 +611,10 @@ class PostgresBinaryEncoder {
608611 writer.writeInt32 (1 ); // index
609612
610613 for (final i in value) {
614+ if (i == null ) {
615+ writer.writeInt32 (- 1 );
616+ continue ;
617+ }
611618 final len = lengthEncoder (i);
612619 writer.writeInt32 (len);
613620 valueEncoder (writer, i);
0 commit comments