@@ -67,9 +67,7 @@ void main() {
67
67
```
68
68
69
69
<details >
70
- <summary >
71
- <b >Solution for string interpolation example</b >
72
- </summary >
70
+ <summary >Solution for string interpolation example</summary >
73
71
74
72
Both ` x ` and ` y ` are simple values,
75
73
and Dart's string interpolation will handle
@@ -82,6 +80,7 @@ void main() {
82
80
return '$x $y';
83
81
}
84
82
```
83
+
85
84
</details >
86
85
87
86
@@ -149,9 +148,7 @@ void main() {
149
148
```
150
149
151
150
<details >
152
- <summary >
153
- <b >Solution for nullable variables example</b >
154
- </summary >
151
+ <summary >Solution for nullable variables example</summary >
155
152
156
153
Declare the two variables as ` String ` followed by ` ? ` .
157
154
Then, assign ` 'Jane' ` to ` name `
@@ -161,6 +158,7 @@ void main() {
161
158
String? name = 'Jane';
162
159
String? address;
163
160
```
161
+
164
162
</details >
165
163
166
164
@@ -233,9 +231,7 @@ void main() {
233
231
```
234
232
235
233
<details >
236
- <summary >
237
- <b >Solution for null-aware operators example</b >
238
- </summary >
234
+ <summary >Solution for null-aware operators example</summary >
239
235
240
236
All you need to do in this exercise is
241
237
replace the ` TODO ` comments with either ` ?? ` or ` ??= ` .
@@ -251,6 +247,7 @@ void main() {
251
247
bar ??= 'a string';
252
248
}
253
249
```
250
+
254
251
</details >
255
252
256
253
@@ -324,9 +321,7 @@ void main() {
324
321
```
325
322
326
323
<details >
327
- <summary >
328
- <b >Solution for conditional property access example</b >
329
- </summary >
324
+ <summary >Solution for conditional property access example</summary >
330
325
331
326
If this exercise wanted you to conditionally lowercase a string,
332
327
you could do it like this: ` str?.toLowerCase() ` . Use the equivalent
@@ -337,6 +332,7 @@ void main() {
337
332
return str?.toUpperCase();
338
333
}
339
334
```
335
+
340
336
</details >
341
337
342
338
## Collection literals
@@ -455,9 +451,7 @@ void main() {
455
451
```
456
452
457
453
<details >
458
- <summary >
459
- <b >Solution for collection literals example</b >
460
- </summary >
454
+ <summary >Solution for collection literals example</summary >
461
455
462
456
Add a list, set, or map literal after each equals sign.
463
457
Remember to specify the types for the empty declarations,
@@ -482,6 +476,7 @@ void main() {
482
476
// Assign this an empty Map of double to int:
483
477
final anEmptyMapOfDoublesToInts = <double, int>{};
484
478
```
479
+
485
480
</details >
486
481
487
482
## Arrow syntax
@@ -576,9 +571,7 @@ void main() {
576
571
```
577
572
578
573
<details >
579
- <summary >
580
- <b >Solution for arrow syntax example</b >
581
- </summary >
574
+ <summary >Solution for arrow syntax example</summary >
582
575
583
576
For the product, you can use ` * ` to multiply the three values together.
584
577
For ` incrementValue1 ` , you can use the increment operator (` ++ ` ).
@@ -729,9 +722,7 @@ void main() {
729
722
```
730
723
731
724
<details >
732
- <summary >
733
- <b >Solution for cascades example</b >
734
- </summary >
725
+ <summary >Solution for cascades example</summary >
735
726
736
727
The best solution for this exercise starts with ` obj.. ` and
737
728
has four assignment operations chained together.
@@ -874,9 +865,8 @@ void main() {
874
865
```
875
866
876
867
<details >
877
- <summary >
878
- <b >Solution for getters and setters example</b >
879
- </summary >
868
+ <summary >Solution for getters and setters example</summary >
869
+
880
870
Two functions are handy for this exercise.
881
871
One is ` fold ` , which can reduce a list to a single value
882
872
(use it to calculate the total).
@@ -897,6 +887,7 @@ void main() {
897
887
_prices = value;
898
888
}
899
889
```
890
+
900
891
</details >
901
892
902
893
@@ -1020,9 +1011,8 @@ void main() {
1020
1011
```
1021
1012
1022
1013
<details >
1023
- <summary >
1024
- <b >Solution for positional parameters example</b >
1025
- </summary >
1014
+ <summary >Solution for positional parameters example</summary >
1015
+
1026
1016
The ` b ` , ` c ` , ` d ` , and ` e ` parameters are null if they aren't provided by the
1027
1017
caller. The important thing, then, is to check whether those arguments are ` null `
1028
1018
before you add them to the final string.
@@ -1037,6 +1027,7 @@ void main() {
1037
1027
return total;
1038
1028
}
1039
1029
```
1030
+
1040
1031
</details >
1041
1032
1042
1033
<a id =" optional-named-parameters " ></a >
@@ -1165,9 +1156,8 @@ void main() {
1165
1156
```
1166
1157
1167
1158
<details >
1168
- <summary >
1169
- <b >Solution for named parameters example</b >
1170
- </summary >
1159
+ <summary >Solution for named parameters example</summary >
1160
+
1171
1161
The ` copyWith ` method shows up in a lot of classes and libraries.
1172
1162
Yours should do a few things:
1173
1163
use optional named parameters,
@@ -1387,9 +1377,8 @@ void main() {
1387
1377
```
1388
1378
1389
1379
<details >
1390
- <summary >
1391
- <b >Solution for exceptions example</b >
1392
- </summary >
1380
+ <summary >Solution for exceptions example</summary >
1381
+
1393
1382
This exercise looks tricky, but it's really one big ` try ` statement.
1394
1383
Call ` untrustworthy ` inside the ` try ` , and
1395
1384
then use ` on ` , ` catch ` , and ` finally ` to catch exceptions and
@@ -1408,6 +1397,7 @@ void main() {
1408
1397
}
1409
1398
}
1410
1399
```
1400
+
1411
1401
</details >
1412
1402
1413
1403
@@ -1504,9 +1494,8 @@ void main() {
1504
1494
```
1505
1495
1506
1496
<details >
1507
- <summary >
1508
- <b >Solution for ` this ` example</b >
1509
- </summary >
1497
+ <summary >Solution for `this` example</summary >
1498
+
1510
1499
This exercise has a one-line solution.
1511
1500
Declare the constructor with
1512
1501
` this.anInt ` , ` this.aString ` , and ` this.aDouble `
@@ -1515,6 +1504,7 @@ void main() {
1515
1504
``` dart
1516
1505
MyClass(this.anInt, this.aString, this.aDouble);
1517
1506
```
1507
+
1518
1508
</details >
1519
1509
1520
1510
{% comment %}
@@ -1628,9 +1618,8 @@ void main() {
1628
1618
```
1629
1619
1630
1620
<details >
1631
- <summary >
1632
- <b >Solution for initializer lists example</b >
1633
- </summary >
1621
+ <summary >Solution for initializer lists example</summary >
1622
+
1634
1623
Two assignments need to happen:
1635
1624
` letterOne ` should be assigned ` word[0] ` ,
1636
1625
and ` letterTwo ` should be assigned ` word[1] ` .
@@ -1726,9 +1715,8 @@ void main() {
1726
1715
```
1727
1716
1728
1717
<details >
1729
- <summary >
1730
- <b >Solution for named constructors example</b >
1731
- </summary >
1718
+ <summary >Solution for named constructors example</summary >
1719
+
1732
1720
The declaration for your constructor should begin with ` Color.black(): ` .
1733
1721
In the initializer list (after the colon), set ` red ` , ` green ` , and ` blue ` to ` 0 ` .
1734
1722
@@ -1738,6 +1726,7 @@ void main() {
1738
1726
green = 0,
1739
1727
blue = 0;
1740
1728
```
1729
+
1741
1730
</details >
1742
1731
1743
1732
## Factory constructors
@@ -1893,9 +1882,8 @@ void main() {
1893
1882
```
1894
1883
1895
1884
<details >
1896
- <summary >
1897
- <b >Solution for factory constructors example</b >
1898
- </summary >
1885
+ <summary >Solution for factory constructors example</summary >
1886
+
1899
1887
Inside the factory constructor,
1900
1888
check the length of the list, then create and return an
1901
1889
` IntegerSingle ` , ` IntegerDouble ` , or ` IntegerTriple ` as appropriate.
@@ -1913,6 +1901,7 @@ void main() {
1913
1901
}
1914
1902
}
1915
1903
```
1904
+
1916
1905
</details >
1917
1906
1918
1907
## Redirecting constructors
@@ -1993,14 +1982,14 @@ void main() {
1993
1982
```
1994
1983
1995
1984
<details >
1996
- <summary >
1997
- <b >Solution for redirecting constructors example</b >
1998
- </summary >
1985
+ <summary >Solution for redirecting constructors example</summary >
1986
+
1999
1987
Your constructor should redirect to ` this(0, 0, 0) ` .
2000
1988
2001
1989
``` dart
2002
1990
Color.black() : this(0, 0, 0);
2003
1991
```
1992
+
2004
1993
</details >
2005
1994
2006
1995
## Const constructors
@@ -2077,9 +2066,8 @@ void main() {
2077
2066
```
2078
2067
2079
2068
<details >
2080
- <summary >
2081
- <b >Solution for const constructors example</b >
2082
- </summary >
2069
+ <summary >Solution for const constructors example</summary >
2070
+
2083
2071
To make the constructor const, you'll need to make all the properties final.
2084
2072
2085
2073
``` dart
@@ -2091,6 +2079,7 @@ void main() {
2091
2079
const Recipe(this.ingredients, this.calories, this.milligramsOfSodium);
2092
2080
}
2093
2081
```
2082
+
2094
2083
</details >
2095
2084
2096
2085
## What's next?
0 commit comments