@@ -248,7 +248,7 @@ class PostgresBinaryEncoder {
248
248
);
249
249
}
250
250
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 }' );
252
252
}
253
253
254
254
case TypeOid .point:
@@ -358,7 +358,7 @@ class PostgresBinaryEncoder {
358
358
);
359
359
}
360
360
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 }' );
362
362
}
363
363
364
364
case TypeOid .smallIntegerArray:
@@ -373,7 +373,7 @@ class PostgresBinaryEncoder {
373
373
);
374
374
}
375
375
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 }' );
377
377
}
378
378
379
379
case TypeOid .integerArray:
@@ -388,7 +388,7 @@ class PostgresBinaryEncoder {
388
388
);
389
389
}
390
390
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 }' );
392
392
}
393
393
394
394
case TypeOid .bigIntegerArray:
@@ -403,7 +403,7 @@ class PostgresBinaryEncoder {
403
403
);
404
404
}
405
405
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 }' );
407
407
}
408
408
409
409
case TypeOid .dateArray:
@@ -419,7 +419,7 @@ class PostgresBinaryEncoder {
419
419
);
420
420
}
421
421
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 }' );
423
423
}
424
424
425
425
case TypeOid .timeArray:
@@ -434,7 +434,7 @@ class PostgresBinaryEncoder {
434
434
);
435
435
}
436
436
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 }' );
438
438
}
439
439
440
440
case TypeOid .timestampArray:
@@ -450,7 +450,7 @@ class PostgresBinaryEncoder {
450
450
);
451
451
}
452
452
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 }' );
454
454
}
455
455
456
456
case TypeOid .timestampTzArray:
@@ -466,14 +466,15 @@ class PostgresBinaryEncoder {
466
466
);
467
467
}
468
468
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 }' );
470
470
}
471
471
472
472
case TypeOid .varCharArray:
473
473
{
474
474
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 ();
477
478
return _writeListBytes <List <int >>(
478
479
bytesArray,
479
480
1043 ,
@@ -483,14 +484,15 @@ class PostgresBinaryEncoder {
483
484
);
484
485
}
485
486
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 }' );
487
488
}
488
489
489
490
case TypeOid .textArray:
490
491
{
491
492
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 ();
494
496
return _writeListBytes <List <int >>(
495
497
bytesArray,
496
498
25 ,
@@ -500,7 +502,7 @@ class PostgresBinaryEncoder {
500
502
);
501
503
}
502
504
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 }' );
504
506
}
505
507
506
508
case TypeOid .doubleArray:
@@ -515,13 +517,14 @@ class PostgresBinaryEncoder {
515
517
);
516
518
}
517
519
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 }' );
519
521
}
520
522
521
523
case TypeOid .jsonbArray:
522
524
{
523
525
if (input is List ) {
524
- final objectsArray = input.map (_jsonFusedEncoding (encoding).encode);
526
+ final objectsArray =
527
+ input.map (_jsonFusedEncoding (encoding).encode).toList ();
525
528
return _writeListBytes <List <int >>(
526
529
objectsArray,
527
530
3802 ,
@@ -581,19 +584,19 @@ class PostgresBinaryEncoder {
581
584
throw ArgumentError ('Cannot encode `$input ` into oid($_typeOid ).' );
582
585
}
583
586
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 ? >) {
586
589
return input;
587
590
}
588
- if (input.any ((e) => e is ! V )) {
591
+ if (input.any ((e) => e is ! V ? )) {
589
592
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 }' );
591
594
}
592
- return input.cast <V >();
595
+ return input.cast <V ? >();
593
596
}
594
597
595
598
Uint8List _writeListBytes <V >(
596
- Iterable < V > value,
599
+ List < V ? > value,
597
600
int type,
598
601
int Function (V item) lengthEncoder,
599
602
void Function (PgByteDataWriter writer, V item) valueEncoder,
@@ -608,6 +611,10 @@ class PostgresBinaryEncoder {
608
611
writer.writeInt32 (1 ); // index
609
612
610
613
for (final i in value) {
614
+ if (i == null ) {
615
+ writer.writeInt32 (- 1 );
616
+ continue ;
617
+ }
611
618
final len = lengthEncoder (i);
612
619
writer.writeInt32 (len);
613
620
valueEncoder (writer, i);
0 commit comments