Skip to content

Commit 8d533e3

Browse files
committed
adjust code excerpt
1 parent bc31e98 commit 8d533e3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

examples/misc/lib/effective_dart/usage_good.dart

+8-7
Original file line numberDiff line numberDiff line change
@@ -358,22 +358,23 @@ class UploadException {
358358

359359
@override
360360
String toString() {
361-
// #enddocregion null-check-promo
362-
final response = this.response;
363-
if (response != null) {
361+
// #enddocregion shadow-nullable-field
362+
if (this.response case var response?) {
364363
return 'Could not complete upload to ${response.url} '
365364
'(error code ${response.errorCode}): ${response.reason}.';
366365
}
367-
// #docregion null-check-promo
368-
if (this.response case var response?) {
366+
// #enddocregion null-check-promo
367+
// #docregion shadow-nullable-field
368+
final response = this.response;
369+
if (response != null) {
369370
return 'Could not complete upload to ${response.url} '
370371
'(error code ${response.errorCode}): ${response.reason}.';
371372
}
372-
373+
// #docregion null-check-promo
373374
return 'Could not upload (no response).';
374375
}
375376
}
376-
// #enddocregion shadow-nullable-field
377+
// #enddocregion shadow-nullable-field, null-check-promo
377378

378379
//----------------------------------------------------------------------------
379380

src/content/effective-dart/usage.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ then it probably does make sense to have a separate boolean field.
326326

327327

328328
### CONSIDER work arounds to bypass type promotion limitations
329-
(or, "...to enable type promotion")
330329

331330
Checking that a nullable variable is not equal to `null` promotes the variable
332331
to a non-nullable type. That lets you access members on the variable and pass it
@@ -356,7 +355,7 @@ class UploadException {
356355
return 'Could not complete upload to ${response.url} '
357356
'(error code ${response.errorCode}): ${response.reason}.';
358357
}
359-
358+
// ···
360359
return 'Could not upload (no response).';
361360
}
362361
}
@@ -375,12 +374,12 @@ class UploadException {
375374
376375
@override
377376
String toString() {
377+
// ···
378378
final response = this.response;
379379
if (response != null) {
380380
return 'Could not complete upload to ${response.url} '
381381
'(error code ${response.errorCode}): ${response.reason}.';
382382
}
383-
384383
return 'Could not upload (no response).';
385384
}
386385
}

0 commit comments

Comments
 (0)