waft-material 0.14.0

Material Design widgets for Waft
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
//! Flutter counterpart: material_ui's `material_localizations.dart`.
//!
//! US English only: [`DefaultMaterialLocalizations`] is the one implementation, and its
//! delegate supports `en`.

use std::fmt;
use std::rc::Rc;

use waft_embedder::Locale;
use waft_foundation::{App, CompleterFuture, DateTime};
use waft_widgets::{BuildContext, Localizations, LocalizationsDelegate, LocalizationsDelegateRef};

use crate::debug::debug_check_has_material_localizations;
use crate::time::{DayPeriod, TimeOfDay, TimeOfDayFormat};
use crate::typography::ScriptCategory;

/// Defines the localized resource values used by the Material widgets.
///
/// See also:
///
///  * [`DefaultMaterialLocalizations`], the default, English-only, implementation
///    of this interface.
///  * `GlobalMaterialLocalizations`, which provides material localizations for
///    many languages.
pub trait MaterialLocalizations: 'static {
    /// The tooltip for the leading `AppBar` menu (a.k.a. 'hamburger') button.
    fn open_app_drawer_tooltip(&self) -> String;

    /// The `BackButton`'s tooltip.
    fn back_button_tooltip(&self) -> String;

    /// The tooltip for the clear button to clear text on `SearchAnchor`'s search view.
    fn clear_button_tooltip(&self) -> String;

    /// The `CloseButton`'s tooltip.
    fn close_button_tooltip(&self) -> String;

    /// The tooltip for the delete button on a `Chip`.
    fn delete_button_tooltip(&self) -> String;

    /// The tooltip for the more button on an overflowing text selection menu.
    fn more_button_tooltip(&self) -> String;

    /// The tooltip for the `CalendarDatePicker`'s "next month" button.
    fn next_month_tooltip(&self) -> String;

    /// The tooltip for the `CalendarDatePicker`'s "previous month" button.
    fn previous_month_tooltip(&self) -> String;

    /// The tooltip for the `PaginatedDataTable`'s "first page" button.
    fn first_page_tooltip(&self) -> String;

    /// The tooltip for the `PaginatedDataTable`'s "last page" button.
    fn last_page_tooltip(&self) -> String;

    /// The tooltip for the `PaginatedDataTable`'s "next page" button.
    fn next_page_tooltip(&self) -> String;

    /// The tooltip for the `PaginatedDataTable`'s "previous page" button.
    fn previous_page_tooltip(&self) -> String;

    /// The default `PopupMenuButton` tooltip.
    fn show_menu_tooltip(&self) -> String;

    /// The default title for `AboutListTile`.
    fn about_list_tile_title(&self, application_name: &str) -> String;

    /// Title for the `LicensePage` widget.
    fn licenses_page_title(&self) -> String;

    /// Subtitle for a package in the `LicensePage` widget.
    fn licenses_package_detail_text(&self, license_count: i32) -> String;

    /// Title for the `PaginatedDataTable`'s row info footer.
    fn page_rows_info_title(
        &self,
        first_row: i32,
        last_row: i32,
        row_count: i32,
        row_count_is_approximate: bool,
    ) -> String;

    /// Title for the `PaginatedDataTable`'s "rows per page" footer.
    fn rows_per_page_title(&self) -> String;

    /// The accessibility label used on a tab in a `TabBar`.
    ///
    /// This message describes the index of the selected tab and how many tabs
    /// there are, e.g. 'Tab 1 of 2' in United States English.
    ///
    /// `tab_index` and `tab_count` must be greater than or equal to one.
    fn tab_label(&self, tab_index: i32, tab_count: i32) -> String;

    /// Title for the `PaginatedDataTable`'s selected row count header.
    fn selected_row_count_title(&self, selected_row_count: i32) -> String;

    /// Label for "cancel" buttons and menu items.
    fn cancel_button_label(&self) -> String;

    /// Label for "close" buttons and menu items.
    fn close_button_label(&self) -> String;

    /// Label for "continue" buttons and menu items.
    fn continue_button_label(&self) -> String;

    /// Label for "copy" edit buttons and menu items.
    fn copy_button_label(&self) -> String;

    /// Label for "cut" edit buttons and menu items.
    fn cut_button_label(&self) -> String;

    /// Label for "scan text" OCR edit buttons and menu items.
    fn scan_text_button_label(&self) -> String;

    /// Label for OK buttons and menu items.
    fn ok_button_label(&self) -> String;

    /// Label for "paste" edit buttons and menu items.
    fn paste_button_label(&self) -> String;

    /// Label for "select all" edit buttons and menu items.
    fn select_all_button_label(&self) -> String;

    /// Label for "look up" edit buttons and menu items.
    fn look_up_button_label(&self) -> String;

    /// Label for "search web" edit buttons and menu items.
    fn search_web_button_label(&self) -> String;

    /// Label for "share" edit buttons and menu items.
    fn share_button_label(&self) -> String;

    /// Label for the `AboutDialog` button that shows the `LicensePage`.
    fn view_licenses_button_label(&self) -> String;

    /// The abbreviation for ante meridiem (before noon) shown in the time picker.
    fn ante_meridiem_abbreviation(&self) -> String;

    /// The abbreviation for post meridiem (after noon) shown in the time picker.
    fn post_meridiem_abbreviation(&self) -> String;

    /// The text-to-speech announcement made when a time picker invoked using
    /// `showTimePicker` is set to the hour picker mode.
    fn time_picker_hour_mode_announcement(&self) -> String;

    /// The text-to-speech announcement made when a time picker invoked using
    /// `showTimePicker` is set to the minute picker mode.
    fn time_picker_minute_mode_announcement(&self) -> String;

    /// Label read out by accessibility tools (TalkBack or VoiceOver) for a modal
    /// barrier to indicate that a tap dismisses the barrier.
    ///
    /// A modal barrier can for example be found behind an alert or popup to block
    /// user interaction with elements behind it.
    fn modal_barrier_dismiss_label(&self) -> String;

    /// Label read out by accessibility tools (TalkBack or VoiceOver) for a
    /// context menu to indicate that a tap dismisses the context menu.
    fn menu_dismiss_label(&self) -> String;

    /// Label read out by accessibility tools (TalkBack or VoiceOver) when a
    /// drawer widget is opened.
    fn drawer_label(&self) -> String;

    /// Label read out by accessibility tools (TalkBack or VoiceOver) when a
    /// popup menu widget is opened.
    fn popup_menu_label(&self) -> String;

    /// Label read out by accessibility tools (TalkBack or VoiceOver) when a
    /// MenuBarMenu widget is opened.
    fn menu_bar_menu_label(&self) -> String;

    /// Label read out by accessibility tools (TalkBack or VoiceOver) when a
    /// dialog widget is opened.
    fn dialog_label(&self) -> String;

    /// Label read out by accessibility tools (TalkBack or VoiceOver) when an
    /// alert dialog widget is opened.
    fn alert_dialog_label(&self) -> String;

    /// Label indicating that a text field is a search field. This will be used
    /// as a hint text in the text field.
    fn search_field_label(&self) -> String;

    /// Label indicating that a given date is the current date.
    fn current_date_label(&self) -> String;

    /// The semantics label to describe the selected date in the calendar picker
    /// invoked using `showDatePicker`.
    fn selected_date_label(&self) -> String;

    /// Label for the scrim rendered underneath a `BottomSheet`.
    fn scrim_label(&self) -> String;

    /// Label for a `BottomSheet`, used as the `modalRouteContentName` of the
    /// [`scrim_on_tap_hint`](Self::scrim_on_tap_hint).
    fn bottom_sheet_label(&self) -> String;

    /// Hint text announced when tapping on the scrim underneath the content of
    /// a modal route.
    fn scrim_on_tap_hint(&self, modal_route_content_name: &str) -> String;

    /// The format used to lay out the time picker.
    ///
    /// The documentation for [`TimeOfDayFormat`] enum values provides details on
    /// each supported layout.
    fn time_of_day_format(&self, always_use_24_hour_format: bool) -> TimeOfDayFormat;

    /// Defines the localized `TextStyle` geometry for `ThemeData.textTheme`.
    ///
    /// The [`script_category`](Self::script_category) defines the overall geometry of a `TextTheme` for
    /// the `Typography.geometryThemeFor` method in terms of the
    /// three language categories defined in <https://material.io/go/design-typography>.
    ///
    /// Generally speaking, font sizes for [`ScriptCategory::Tall`] and
    /// [`ScriptCategory::Dense`] scripts - for text styles that are smaller than the
    /// title style - are one unit larger than they are for
    /// [`ScriptCategory::EnglishLike`] scripts.
    fn script_category(&self) -> ScriptCategory;

    /// Formats `number` as a decimal, inserting locale-appropriate thousands
    /// separators as necessary.
    fn format_decimal(&self, number: i64) -> String;

    /// Formats [`hour`](TimeOfDay::hour) in the given time of day according to the value
    /// of [`time_of_day_format`](Self::time_of_day_format).
    ///
    /// If `always_use_24_hour_format` is true, formats hour using [`HourFormat::HH`](crate::HourFormat::HH)
    /// rather than the default for the current locale.
    fn format_hour(&self, time_of_day: &TimeOfDay, always_use_24_hour_format: bool) -> String;

    /// Formats [`minute`](TimeOfDay::minute) in the given time of day according to the value
    /// of [`time_of_day_format`](Self::time_of_day_format).
    fn format_minute(&self, time_of_day: &TimeOfDay) -> String;

    /// Formats `time_of_day` according to the value of [`time_of_day_format`](Self::time_of_day_format).
    ///
    /// If `always_use_24_hour_format` is true, formats hour using [`HourFormat::HH`](crate::HourFormat::HH)
    /// rather than the default for the current locale. This value is usually
    /// passed from `MediaQueryData.alwaysUse24HourFormat`, which has platform-
    /// specific behavior.
    fn format_time_of_day(
        &self,
        time_of_day: &TimeOfDay,
        always_use_24_hour_format: bool,
    ) -> String;

    /// Full unabbreviated year format, e.g. 2017 rather than 17.
    fn format_year(&self, app: &App, date: &DateTime) -> String;

    /// Formats the date in a compact format.
    ///
    /// Usually just the numeric values for the for day, month and year are used.
    ///
    /// Examples:
    ///
    /// - US English: 02/21/2019
    /// - Russian: 21.02.2019
    ///
    /// See also:
    ///   * [`parse_compact_date`](Self::parse_compact_date), which will convert a compact date string to a [`DateTime`].
    fn format_compact_date(&self, app: &App, date: &DateTime) -> String;

    /// Formats the date using a short-width format.
    ///
    /// Includes the abbreviation of the month, the day and year.
    ///
    /// Examples:
    ///
    /// - US English: Feb 21, 2019
    /// - Russian: 21 февр. 2019 г.
    fn format_short_date(&self, app: &App, date: &DateTime) -> String;

    /// Formats the date using a medium-width format.
    ///
    /// Abbreviates month and days of week. This appears in the header of the date
    /// picker invoked using `showDatePicker`.
    ///
    /// Examples:
    ///
    /// - US English: Wed, Sep 27
    /// - Russian: ср, сент. 27
    fn format_medium_date(&self, app: &App, date: &DateTime) -> String;

    /// Formats day of week, month, day of month and year in a long-width format.
    ///
    /// Does not abbreviate names. Appears in spoken announcements of the date
    /// picker invoked using `showDatePicker`, when accessibility mode is on.
    ///
    /// Examples:
    ///
    /// - US English: Wednesday, September 27, 2017
    /// - Russian: Среда, Сентябрь 27, 2017
    fn format_full_date(&self, app: &App, date: &DateTime) -> String;

    /// Formats the month and the year of the given `date`.
    ///
    /// The returned string does not contain the day of the month. This appears
    /// in the date picker invoked using `showDatePicker`.
    fn format_month_year(&self, app: &App, date: &DateTime) -> String;

    /// Formats the month and day of the given `date`.
    ///
    /// Examples:
    ///
    /// - US English: Feb 21
    /// - Russian: 21 февр.
    fn format_short_month_day(&self, app: &App, date: &DateTime) -> String;

    /// Converts the given compact date formatted string into a [`DateTime`].
    ///
    /// The format of the string must be a valid compact date format for the
    /// given locale. If the text doesn't represent a valid date, `None` will be
    /// returned.
    ///
    /// See also:
    ///   * [`format_compact_date`](Self::format_compact_date), which will convert a [`DateTime`] into a string in the compact format.
    fn parse_compact_date(&self, app: &App, input_string: Option<&str>) -> Option<DateTime>;

    /// List of week day names in narrow format, usually 1- or 2-letter
    /// abbreviations of full names.
    ///
    /// The list begins with the value corresponding to Sunday and ends with
    /// Saturday. Use [`first_day_of_week_index`](Self::first_day_of_week_index) to find the first day of week in this
    /// list.
    ///
    /// Examples:
    ///
    /// - US English: S, M, T, W, T, F, S
    /// - Russian: вс, пн, вт, ср, чт, пт, сб - notice that the list begins with
    ///   вс (Sunday) even though the first day of week for Russian is Monday.
    fn narrow_weekdays(&self) -> Vec<String>;

    /// Index of the first day of week, where 0 points to Sunday, and 6 points to
    /// Saturday.
    ///
    /// This getter is compatible with [`narrow_weekdays`](Self::narrow_weekdays). For example:
    ///
    /// ```text
    /// let localizations = <dyn MaterialLocalizations>::of(app, context);
    /// // The name of the first day of week for the current locale.
    /// let first_day_of_week = &localizations.narrow_weekdays()[localizations.first_day_of_week_index() as usize];
    /// ```
    fn first_day_of_week_index(&self) -> i32;

    /// The character string used to separate the parts of a compact date format
    /// (i.e. mm/dd/yyyy has a separator of '/').
    fn date_separator(&self) -> String;

    /// The help text used on an empty `InputDatePickerFormField` to indicate
    /// to the user the date format being asked for.
    fn date_help_text(&self) -> String;

    /// The semantic label used to announce when the user has entered the year
    /// selection mode of the `CalendarDatePicker` which is used in the data picker
    /// dialog created with `showDatePicker`.
    fn select_year_semantics_label(&self) -> String;

    /// The label used to indicate a date that has not been entered or selected
    /// yet in the date picker.
    fn unspecified_date(&self) -> String;

    /// The label used to indicate a date range that has not been entered or
    /// selected yet in the date range picker.
    fn unspecified_date_range(&self) -> String;

    /// The label used to describe the text field used in an `InputDatePickerFormField`.
    fn date_input_label(&self) -> String;

    /// The label used for the starting date input field in the date range picker
    /// created with `showDateRangePicker`.
    fn date_range_start_label(&self) -> String;

    /// The label used for the ending date input field in the date range picker
    /// created with `showDateRangePicker`.
    fn date_range_end_label(&self) -> String;

    /// The semantics label used for the selected start date in the date range
    /// picker's day grid.
    fn date_range_start_date_semantic_label(&self, formatted_date: &str) -> String;

    /// The semantics label used for the selected end date in the date range
    /// picker's day grid.
    fn date_range_end_date_semantic_label(&self, formatted_date: &str) -> String;

    /// Error message displayed to the user when they have entered a text string
    /// in an `InputDatePickerFormField` that is not in a valid date format.
    fn invalid_date_format_label(&self) -> String;

    /// Error message displayed to the user when they have entered an invalid
    /// date range in the input mode of the date range picker created with
    /// `showDateRangePicker`.
    fn invalid_date_range_label(&self) -> String;

    /// Error message displayed to the user when they have entered a date that
    /// is outside the valid range for the date picker.
    /// `showDateRangePicker`.
    fn date_out_of_range_label(&self) -> String;

    /// Label for a 'SAVE' button. Currently used by the full screen mode of the
    /// date range picker.
    fn save_button_label(&self) -> String;

    /// Label used in the header of the date picker dialog created with
    /// `showDatePicker`.
    fn date_picker_help_text(&self) -> String;

    /// Label used in the header of the date range picker dialog created with
    /// `showDateRangePicker`.
    fn date_range_picker_help_text(&self) -> String;

    /// Tooltip used for the calendar mode button of the date pickers.
    fn calendar_mode_button_label(&self) -> String;

    /// Tooltip used for the text input mode button of the date pickers.
    fn input_date_mode_button_label(&self) -> String;

    /// Label used in the header of the time picker dialog created with
    /// `showTimePicker` when in `TimePickerEntryMode.dial`.
    fn time_picker_dial_help_text(&self) -> String;

    /// Label used in the header of the time picker dialog created with
    /// `showTimePicker` when in `TimePickerEntryMode.input`.
    fn time_picker_input_help_text(&self) -> String;

    /// Label used below the hour text field of the time picker dialog created
    /// with `showTimePicker` when in `TimePickerEntryMode.input`.
    fn time_picker_hour_label(&self) -> String;

    /// Label used below the minute text field of the time picker dialog created
    /// with `showTimePicker` when in `TimePickerEntryMode.input`.
    fn time_picker_minute_label(&self) -> String;

    /// Error message for the time picker dialog created with `showTimePicker`
    /// when in `TimePickerEntryMode.input`.
    fn invalid_time_label(&self) -> String;

    /// Tooltip used to put the time picker into `TimePickerEntryMode.dial`.
    fn dial_mode_button_label(&self) -> String;

    /// Tooltip used to put the time picker into `TimePickerEntryMode.input`.
    fn input_time_mode_button_label(&self) -> String;

    /// The semantics label used to indicate which account is signed in the
    /// `UserAccountsDrawerHeader` widget.
    fn signed_in_label(&self) -> String;

    /// The semantics label used for the button on `UserAccountsDrawerHeader` that
    /// hides the list of accounts.
    fn hide_accounts_label(&self) -> String;

    /// The semantics label used for the button on `UserAccountsDrawerHeader` that
    /// shows the list of accounts.
    fn show_accounts_label(&self) -> String;

    /// The semantics label used for `ReorderableListView` to reorder an item in the
    /// list to the start of the list.
    #[deprecated(
        note = "Use the reorderItemToStart from WidgetsLocalizations instead. This feature was deprecated after v3.10.0-2.0.pre."
    )]
    fn reorder_item_to_start(&self) -> String;

    /// The semantics label used for `ReorderableListView` to reorder an item in the
    /// list to the end of the list.
    #[deprecated(
        note = "Use the reorderItemToEnd from WidgetsLocalizations instead. This feature was deprecated after v3.10.0-2.0.pre."
    )]
    fn reorder_item_to_end(&self) -> String;

    /// The semantics label used for `ReorderableListView` to reorder an item in the
    /// list one space up the list.
    #[deprecated(
        note = "Use the reorderItemUp from WidgetsLocalizations instead. This feature was deprecated after v3.10.0-2.0.pre."
    )]
    fn reorder_item_up(&self) -> String;

    /// The semantics label used for `ReorderableListView` to reorder an item in the
    /// list one space down the list.
    #[deprecated(
        note = "Use the reorderItemDown from WidgetsLocalizations instead. This feature was deprecated after v3.10.0-2.0.pre."
    )]
    fn reorder_item_down(&self) -> String;

    /// The semantics label used for `ReorderableListView` to reorder an item in the
    /// list one space left in the list.
    #[deprecated(
        note = "Use the reorderItemLeft from WidgetsLocalizations instead. This feature was deprecated after v3.10.0-2.0.pre."
    )]
    fn reorder_item_left(&self) -> String;

    /// The semantics label used for `ReorderableListView` to reorder an item in the
    /// list one space right in the list.
    #[deprecated(
        note = "Use the reorderItemRight from WidgetsLocalizations instead. This feature was deprecated after v3.10.0-2.0.pre."
    )]
    fn reorder_item_right(&self) -> String;

    /// The semantics hint to describe the tap action on an expanded `ExpandIcon`.
    fn expanded_icon_tap_hint(&self) -> String {
        String::from("Collapse")
    }

    /// The semantics hint to describe the tap action on a collapsed `ExpandIcon`.
    fn collapsed_icon_tap_hint(&self) -> String {
        String::from("Expand")
    }

    /// The semantics hint to describe the tap action on an expanded
    /// `ExpansionTile` on iOS and macOS. This is appended to the [`collapsed_hint`](Self::collapsed_hint)
    /// hint to provide a more detailed description of the action, e.g. "Expanded
    /// double tap to collapse".
    fn expansion_tile_expanded_hint(&self) -> String {
        String::from("double tap to collapse")
    }

    /// The semantics hint to describe the tap action on a collapsed
    /// `ExpansionTile` on iOS and macOS. This is appended to the [`expanded_hint`](Self::expanded_hint)
    /// hint to provide a more detailed description of the action, e.g. "Collapsed
    /// double tap to expand".
    fn expansion_tile_collapsed_hint(&self) -> String {
        String::from("double tap to expand")
    }

    /// The semantics hint to describe the tap action on an expanded `ExpansionTile`.
    fn expansion_tile_expanded_tap_hint(&self) -> String {
        String::from("Collapse")
    }

    /// The semantics hint to describe the tap action on a collapsed `ExpansionTile`.
    fn expansion_tile_collapsed_tap_hint(&self) -> String {
        String::from("Expand for more details")
    }

    /// The semantics hint to describe the `ExpansionTile` expanded state.
    fn expanded_hint(&self) -> String {
        String::from("Collapsed")
    }

    /// The semantics hint to describe the `ExpansionTile` collapsed state.
    fn collapsed_hint(&self) -> String {
        String::from("Expanded")
    }

    /// The label for the `TextField`'s character counter.
    fn remaining_text_field_character_count(&self, remaining: i32) -> String;

    /// The default semantics label for a `RefreshIndicator`.
    fn refresh_indicator_semantic_label(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.alt`.
    fn keyboard_key_alt(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.altGraph`.
    fn keyboard_key_alt_graph(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.backspace`.
    fn keyboard_key_backspace(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.capsLock`.
    fn keyboard_key_caps_lock(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.channelDown`.
    fn keyboard_key_channel_down(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.channelUp`.
    fn keyboard_key_channel_up(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.control`.
    fn keyboard_key_control(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.delete`.
    fn keyboard_key_delete(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.eject`.
    fn keyboard_key_eject(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.end`.
    fn keyboard_key_end(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.escape`.
    fn keyboard_key_escape(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.fn`.
    fn keyboard_key_fn(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.home`.
    fn keyboard_key_home(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.insert`.
    fn keyboard_key_insert(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.meta`.
    fn keyboard_key_meta(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.meta` on macOS.
    fn keyboard_key_meta_mac_os(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.meta` on Windows.
    fn keyboard_key_meta_windows(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numLock`.
    fn keyboard_key_num_lock(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad1`.
    fn keyboard_key_numpad1(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad2`.
    fn keyboard_key_numpad2(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad3`.
    fn keyboard_key_numpad3(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad4`.
    fn keyboard_key_numpad4(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad5`.
    fn keyboard_key_numpad5(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad6`.
    fn keyboard_key_numpad6(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad7`.
    fn keyboard_key_numpad7(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad8`.
    fn keyboard_key_numpad8(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad9`.
    fn keyboard_key_numpad9(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpad0`.
    fn keyboard_key_numpad0(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadAdd`.
    fn keyboard_key_numpad_add(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadComma`.
    fn keyboard_key_numpad_comma(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadDecimal`.
    fn keyboard_key_numpad_decimal(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadDivide`.
    fn keyboard_key_numpad_divide(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadEnter`.
    fn keyboard_key_numpad_enter(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadEqual`.
    fn keyboard_key_numpad_equal(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadMultiply`.
    fn keyboard_key_numpad_multiply(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadParenLeft`.
    fn keyboard_key_numpad_paren_left(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadParenRight`.
    fn keyboard_key_numpad_paren_right(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.numpadSubtract`.
    fn keyboard_key_numpad_subtract(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.pageDown`.
    fn keyboard_key_page_down(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.pageUp`.
    fn keyboard_key_page_up(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.power`.
    fn keyboard_key_power(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.powerOff`.
    fn keyboard_key_power_off(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.printScreen`.
    fn keyboard_key_print_screen(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.scrollLock`.
    fn keyboard_key_scroll_lock(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.select`.
    fn keyboard_key_select(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.shift`.
    fn keyboard_key_shift(&self) -> String;

    /// The shortcut label for the keyboard key `LogicalKeyboardKey.space`.
    fn keyboard_key_space(&self) -> String;
}

impl dyn MaterialLocalizations {
    /// The `MaterialLocalizations` from the closest [`Localizations`] instance
    /// that encloses the given context.
    ///
    /// If no [`MaterialLocalizations`] are available in the given `context`, this
    /// method throws an exception.
    ///
    /// This method is just a convenient shorthand for:
    /// `Localizations::of::<dyn MaterialLocalizations>(app, context)`.
    ///
    /// References to the localized resources defined by this class are typically
    /// written in terms of this method. For example:
    ///
    /// ```text
    /// tooltip: <dyn MaterialLocalizations>::of(app, context).back_button_tooltip(),
    /// ```
    pub fn of(app: &mut App, context: BuildContext) -> Rc<dyn MaterialLocalizations> {
        debug_assert!(debug_check_has_material_localizations(app, context));
        Localizations::of::<dyn MaterialLocalizations>(app, context)
            .expect("No MaterialLocalizations found.")
    }
}

struct MaterialLocalizationsDelegate;

impl LocalizationsDelegate<dyn MaterialLocalizations> for MaterialLocalizationsDelegate {
    fn is_supported(&self, locale: &Locale) -> bool {
        locale.language_code == "en"
    }

    fn load(
        &self,
        _app: &mut App,
        locale: &Locale,
    ) -> CompleterFuture<Rc<dyn MaterialLocalizations>> {
        DefaultMaterialLocalizations::load(locale)
    }

    fn should_reload(&self, _old: &Self) -> bool {
        false
    }
}

impl fmt::Debug for MaterialLocalizationsDelegate {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str("DefaultMaterialLocalizations.delegate(en_US)")
    }
}

/// US English strings for the material widgets.
///
/// See also:
///
///  * `GlobalMaterialLocalizations`, which provides material localizations for
///    many languages.
///  * `MaterialApp.localizationsDelegates`, which automatically includes
///    [`DefaultMaterialLocalizations::delegate`] by default.
#[derive(Debug, Default)]
pub struct DefaultMaterialLocalizations;

impl DefaultMaterialLocalizations {
    /// Constructs an object that defines the material widgets' localized strings
    /// for US English (only).
    ///
    /// [`LocalizationsDelegate`] implementations typically call the static [`load`](Self::load)
    /// function, rather than constructing this class directly.
    pub const fn new() -> DefaultMaterialLocalizations {
        DefaultMaterialLocalizations
    }

    // Ordered to match DateTime.monday=1, DateTime.sunday=6
    const SHORT_WEEKDAYS: [&str; 7] = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];

    // Ordered to match DateTime.monday=1, DateTime.sunday=6
    const WEEKDAYS: [&str; 7] = [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday",
    ];

    const NARROW_WEEKDAYS: [&str; 7] = ["S", "M", "T", "W", "T", "F", "S"];

    const SHORT_MONTHS: [&str; 12] = [
        "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
    ];

    const MONTHS: [&str; 12] = [
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December",
    ];

    /// Returns the number of days in a month, according to the proleptic
    /// Gregorian calendar.
    ///
    /// This applies the leap year logic introduced by the Gregorian reforms of
    /// 1582. It will not give valid results for dates prior to that time.
    fn get_days_in_month(year: i64, month: i64) -> i64 {
        if month == i64::from(DateTime::FEBRUARY) {
            let is_leap_year = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
            if is_leap_year {
                return 29;
            }
            return 28;
        }
        const DAYS_IN_MONTH: [i64; 12] = [31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        DAYS_IN_MONTH[usize::try_from(month - 1).expect("a month in 1..=12")]
    }

    /// Formats `number` using two digits, assuming it's in the 0-99 inclusive
    /// range. Not designed to format values outside this range.
    fn format_two_digit_zero_pad(number: i32) -> String {
        debug_assert!((0..100).contains(&number));

        if number < 10 {
            return format!("0{number}");
        }

        number.to_string()
    }

    fn format_day_period(&self, time_of_day: &TimeOfDay) -> String {
        match time_of_day.period() {
            DayPeriod::Am => self.ante_meridiem_abbreviation(),
            DayPeriod::Pm => self.post_meridiem_abbreviation(),
        }
    }

    /// Creates an object that provides US English resource values for the material
    /// library widgets.
    ///
    /// The `locale` parameter is ignored.
    ///
    /// This method is typically used to create a [`LocalizationsDelegate`].
    /// The `MaterialApp` does so by default.
    pub fn load(_locale: &Locale) -> CompleterFuture<Rc<dyn MaterialLocalizations>> {
        CompleterFuture::ready(Rc::new(DefaultMaterialLocalizations::new()))
    }

    /// A [`LocalizationsDelegate`] that uses [`DefaultMaterialLocalizations::load`]
    /// to create an instance of this class.
    ///
    /// `MaterialApp` automatically adds this value to `MaterialApp.localizationsDelegates`.
    pub fn delegate() -> LocalizationsDelegateRef {
        LocalizationsDelegateRef::new(MaterialLocalizationsDelegate)
    }
}

/// The index of `date`'s month in a table that starts with January.
fn month_index(app: &App, date: &DateTime) -> usize {
    usize::try_from(date.month(app) - DateTime::JANUARY).expect("a month in 1..=12")
}

/// The index of `date`'s weekday in a table that starts with Monday.
fn weekday_index(app: &App, date: &DateTime) -> usize {
    usize::try_from(date.weekday(app) - DateTime::MONDAY).expect("a weekday in 1..=7")
}

/// Dart's `int.tryParse(source, radix: 10)`: surrounding whitespace (Dart's, which counts
/// U+FEFF) and a sign are accepted, and a value outside 64 bits is `None`.
fn try_parse_int(source: &str) -> Option<i64> {
    source
        .trim_matches(|c: char| c.is_whitespace() || c == '\u{FEFF}')
        .parse()
        .ok()
}

/// Dart's `DateTime(year, month, day)` for a valid date from year 1 on, with the
/// `ArgumentError` it throws past the last day a `DateTime` can represent as `None`.
fn date_time_or_none(app: &App, year: i64, month: i64, day: i64) -> Option<DateTime> {
    // The last instant a `DateTime` holds, 100,000,000 days after the epoch, read in the local
    // zone: a local midnight after its date is out of range.
    const LAST_MILLISECOND: i64 = 8_640_000_000_000_000;
    let last = DateTime::from_milliseconds_since_epoch(LAST_MILLISECOND, false);
    let last_day = (
        i64::from(last.year(app)),
        i64::from(last.month(app)),
        i64::from(last.day(app)),
    );
    if (year, month, day) > last_day {
        return None;
    }
    let field = |value: i64| i32::try_from(value).expect("within the representable range");
    Some(DateTime::new(app, field(year), field(month), field(day)))
}

impl MaterialLocalizations for DefaultMaterialLocalizations {
    fn format_hour(&self, time_of_day: &TimeOfDay, always_use_24_hour_format: bool) -> String {
        let format = self.time_of_day_format(always_use_24_hour_format);
        match format {
            TimeOfDayFormat::h_colon_mm_space_a => {
                self.format_decimal(i64::from(if time_of_day.hour_of_period() == 0 {
                    12
                } else {
                    time_of_day.hour_of_period()
                }))
            }
            TimeOfDayFormat::HH_colon_mm => Self::format_two_digit_zero_pad(time_of_day.hour),
            TimeOfDayFormat::a_space_h_colon_mm
            | TimeOfDayFormat::FrenchCanadian
            | TimeOfDayFormat::H_colon_mm
            | TimeOfDayFormat::HH_dot_mm => {
                panic!("DefaultMaterialLocalizations does not support {format:?}.")
            }
        }
    }

    fn format_minute(&self, time_of_day: &TimeOfDay) -> String {
        let minute = time_of_day.minute;
        if minute < 10 {
            format!("0{minute}")
        } else {
            minute.to_string()
        }
    }

    fn format_year(&self, app: &App, date: &DateTime) -> String {
        date.year(app).to_string()
    }

    fn format_compact_date(&self, app: &App, date: &DateTime) -> String {
        // Assumes US mm/dd/yyyy format
        let month = Self::format_two_digit_zero_pad(date.month(app));
        let day = Self::format_two_digit_zero_pad(date.day(app));
        let year = format!("{:0>4}", date.year(app).to_string());
        format!("{month}/{day}/{year}")
    }

    fn format_short_date(&self, app: &App, date: &DateTime) -> String {
        let month = Self::SHORT_MONTHS[month_index(app, date)];
        format!("{month} {}, {}", date.day(app), date.year(app))
    }

    fn format_medium_date(&self, app: &App, date: &DateTime) -> String {
        let day = Self::SHORT_WEEKDAYS[weekday_index(app, date)];
        let month = Self::SHORT_MONTHS[month_index(app, date)];
        format!("{day}, {month} {}", date.day(app))
    }

    fn format_full_date(&self, app: &App, date: &DateTime) -> String {
        let month = Self::MONTHS[month_index(app, date)];
        format!(
            "{}, {month} {}, {}",
            Self::WEEKDAYS[weekday_index(app, date)],
            date.day(app),
            date.year(app)
        )
    }

    fn format_month_year(&self, app: &App, date: &DateTime) -> String {
        let year = self.format_year(app, date);
        let month = Self::MONTHS[month_index(app, date)];
        format!("{month} {year}")
    }

    fn format_short_month_day(&self, app: &App, date: &DateTime) -> String {
        let month = Self::SHORT_MONTHS[month_index(app, date)];
        format!("{month} {}", date.day(app))
    }

    fn parse_compact_date(&self, app: &App, input_string: Option<&str>) -> Option<DateTime> {
        let input_string = input_string?;

        // Assumes US mm/dd/yyyy format
        let input_parts: Vec<&str> = input_string.split('/').collect();
        if input_parts.len() != 3 {
            return None;
        }

        let year = try_parse_int(input_parts[2]).filter(|&year| year >= 1)?;

        let month = try_parse_int(input_parts[0]).filter(|month| (1..=12).contains(month))?;

        let day = try_parse_int(input_parts[1])
            .filter(|&day| day >= 1 && day <= Self::get_days_in_month(year, month))?;

        date_time_or_none(app, year, month, day)
    }

    fn narrow_weekdays(&self) -> Vec<String> {
        Self::NARROW_WEEKDAYS.map(String::from).to_vec()
    }

    fn first_day_of_week_index(&self) -> i32 {
        0 // narrow_weekdays[0] is 'S' for Sunday
    }

    fn date_separator(&self) -> String {
        String::from("/")
    }

    fn date_help_text(&self) -> String {
        String::from("mm/dd/yyyy")
    }

    fn select_year_semantics_label(&self) -> String {
        String::from("Select year")
    }

    fn unspecified_date(&self) -> String {
        String::from("Date")
    }

    fn unspecified_date_range(&self) -> String {
        String::from("Date Range")
    }

    fn date_input_label(&self) -> String {
        String::from("Enter Date")
    }

    fn date_range_start_label(&self) -> String {
        String::from("Start Date")
    }

    fn date_range_end_label(&self) -> String {
        String::from("End Date")
    }

    fn date_range_start_date_semantic_label(&self, formatted_date: &str) -> String {
        format!("Start date {formatted_date}")
    }

    fn date_range_end_date_semantic_label(&self, formatted_date: &str) -> String {
        format!("End date {formatted_date}")
    }

    fn invalid_date_format_label(&self) -> String {
        String::from("Invalid format.")
    }

    fn invalid_date_range_label(&self) -> String {
        String::from("Invalid range.")
    }

    fn date_out_of_range_label(&self) -> String {
        String::from("Out of range.")
    }

    fn save_button_label(&self) -> String {
        String::from("Save")
    }

    fn date_picker_help_text(&self) -> String {
        String::from("Select date")
    }

    fn date_range_picker_help_text(&self) -> String {
        String::from("Select range")
    }

    fn calendar_mode_button_label(&self) -> String {
        String::from("Switch to calendar")
    }

    fn input_date_mode_button_label(&self) -> String {
        String::from("Switch to input")
    }

    fn time_picker_dial_help_text(&self) -> String {
        String::from("Select time")
    }

    fn time_picker_input_help_text(&self) -> String {
        String::from("Enter time")
    }

    fn time_picker_hour_label(&self) -> String {
        String::from("Hour")
    }

    fn time_picker_minute_label(&self) -> String {
        String::from("Minute")
    }

    fn invalid_time_label(&self) -> String {
        String::from("Enter a valid time")
    }

    fn dial_mode_button_label(&self) -> String {
        String::from("Switch to dial picker mode")
    }

    fn input_time_mode_button_label(&self) -> String {
        String::from("Switch to text input mode")
    }

    fn format_decimal(&self, number: i64) -> String {
        if number > -1000 && number < 1000 {
            return number.to_string();
        }

        // Dart's 64-bit `abs`, under which the smallest int stays negative.
        let digits = number.wrapping_abs().to_string();
        let mut result = String::from(if number < 0 { "-" } else { "" });
        let max_digit_index = digits.len() - 1;
        for (i, digit) in digits.chars().enumerate() {
            result.push(digit);
            if i < max_digit_index && (max_digit_index - i).is_multiple_of(3) {
                result.push(',');
            }
        }
        result
    }

    fn format_time_of_day(
        &self,
        time_of_day: &TimeOfDay,
        always_use_24_hour_format: bool,
    ) -> String {
        // Not using intl.DateFormat for two reasons:
        //
        // - DateFormat supports more formats than our material time picker does,
        //   and we want to be consistent across time picker format and the string
        //   formatting of the time of day.
        // - DateFormat operates on DateTime, which is sensitive to time eras and
        //   time zones, while here we want to format hour and minute within one day
        //   no matter what date the day falls on.
        let mut buffer = String::new();

        // Add hour:minute.
        buffer.push_str(&self.format_hour(time_of_day, always_use_24_hour_format));
        buffer.push(':');
        buffer.push_str(&self.format_minute(time_of_day));

        if always_use_24_hour_format {
            // There's no AM/PM indicator in 24-hour format.
            return buffer;
        }

        // Add AM/PM indicator.
        buffer.push(' ');
        buffer.push_str(&self.format_day_period(time_of_day));
        buffer
    }

    fn open_app_drawer_tooltip(&self) -> String {
        String::from("Open navigation menu")
    }

    fn back_button_tooltip(&self) -> String {
        String::from("Back")
    }

    fn clear_button_tooltip(&self) -> String {
        String::from("Clear text")
    }

    fn close_button_tooltip(&self) -> String {
        String::from("Close")
    }

    fn delete_button_tooltip(&self) -> String {
        String::from("Delete")
    }

    fn more_button_tooltip(&self) -> String {
        String::from("More")
    }

    fn next_month_tooltip(&self) -> String {
        String::from("Next month")
    }

    fn previous_month_tooltip(&self) -> String {
        String::from("Previous month")
    }

    fn next_page_tooltip(&self) -> String {
        String::from("Next page")
    }

    fn previous_page_tooltip(&self) -> String {
        String::from("Previous page")
    }

    fn first_page_tooltip(&self) -> String {
        String::from("First page")
    }

    fn last_page_tooltip(&self) -> String {
        String::from("Last page")
    }

    fn show_menu_tooltip(&self) -> String {
        String::from("Show menu")
    }

    fn drawer_label(&self) -> String {
        String::from("Navigation menu")
    }

    fn menu_bar_menu_label(&self) -> String {
        String::from("Menu bar menu")
    }

    fn popup_menu_label(&self) -> String {
        String::from("Popup menu")
    }

    fn dialog_label(&self) -> String {
        String::from("Dialog")
    }

    fn alert_dialog_label(&self) -> String {
        String::from("Alert")
    }

    fn search_field_label(&self) -> String {
        String::from("Search")
    }

    fn current_date_label(&self) -> String {
        String::from("Today")
    }

    fn selected_date_label(&self) -> String {
        String::from("Selected")
    }

    fn scrim_label(&self) -> String {
        String::from("Scrim")
    }

    fn bottom_sheet_label(&self) -> String {
        String::from("Bottom Sheet")
    }

    fn scrim_on_tap_hint(&self, modal_route_content_name: &str) -> String {
        format!("Close {modal_route_content_name}")
    }

    fn about_list_tile_title(&self, application_name: &str) -> String {
        format!("About {application_name}")
    }

    fn licenses_page_title(&self) -> String {
        String::from("Licenses")
    }

    fn licenses_package_detail_text(&self, license_count: i32) -> String {
        debug_assert!(license_count >= 0);
        match license_count {
            0 => String::from("No licenses."),
            1 => String::from("1 license."),
            _ => format!("{license_count} licenses."),
        }
    }

    fn page_rows_info_title(
        &self,
        first_row: i32,
        last_row: i32,
        row_count: i32,
        row_count_is_approximate: bool,
    ) -> String {
        if row_count_is_approximate {
            format!("{first_row}–{last_row} of about {row_count}")
        } else {
            format!("{first_row}–{last_row} of {row_count}")
        }
    }

    fn rows_per_page_title(&self) -> String {
        String::from("Rows per page:")
    }

    fn tab_label(&self, tab_index: i32, tab_count: i32) -> String {
        debug_assert!(tab_index >= 1);
        debug_assert!(tab_count >= 1);
        format!("Tab {tab_index} of {tab_count}")
    }

    fn selected_row_count_title(&self, selected_row_count: i32) -> String {
        match selected_row_count {
            0 => String::from("No items selected"),
            1 => String::from("1 item selected"),
            _ => format!("{selected_row_count} items selected"),
        }
    }

    fn cancel_button_label(&self) -> String {
        String::from("Cancel")
    }

    fn close_button_label(&self) -> String {
        String::from("Close")
    }

    fn continue_button_label(&self) -> String {
        String::from("Continue")
    }

    fn copy_button_label(&self) -> String {
        String::from("Copy")
    }

    fn cut_button_label(&self) -> String {
        String::from("Cut")
    }

    fn scan_text_button_label(&self) -> String {
        String::from("Scan text")
    }

    fn ok_button_label(&self) -> String {
        String::from("OK")
    }

    fn paste_button_label(&self) -> String {
        String::from("Paste")
    }

    fn select_all_button_label(&self) -> String {
        String::from("Select all")
    }

    fn look_up_button_label(&self) -> String {
        String::from("Look Up")
    }

    fn search_web_button_label(&self) -> String {
        String::from("Search Web")
    }

    fn share_button_label(&self) -> String {
        String::from("Share")
    }

    fn view_licenses_button_label(&self) -> String {
        String::from("View licenses")
    }

    fn ante_meridiem_abbreviation(&self) -> String {
        String::from("AM")
    }

    fn post_meridiem_abbreviation(&self) -> String {
        String::from("PM")
    }

    fn time_picker_hour_mode_announcement(&self) -> String {
        String::from("Select hours")
    }

    fn time_picker_minute_mode_announcement(&self) -> String {
        String::from("Select minutes")
    }

    fn modal_barrier_dismiss_label(&self) -> String {
        String::from("Dismiss")
    }

    fn menu_dismiss_label(&self) -> String {
        String::from("Dismiss menu")
    }

    fn script_category(&self) -> ScriptCategory {
        ScriptCategory::EnglishLike
    }

    fn time_of_day_format(&self, always_use_24_hour_format: bool) -> TimeOfDayFormat {
        if always_use_24_hour_format {
            TimeOfDayFormat::HH_colon_mm
        } else {
            TimeOfDayFormat::h_colon_mm_space_a
        }
    }

    fn signed_in_label(&self) -> String {
        String::from("Signed in")
    }

    fn hide_accounts_label(&self) -> String {
        String::from("Hide accounts")
    }

    fn show_accounts_label(&self) -> String {
        String::from("Show accounts")
    }

    fn reorder_item_up(&self) -> String {
        String::from("Move up")
    }

    fn reorder_item_down(&self) -> String {
        String::from("Move down")
    }

    fn reorder_item_left(&self) -> String {
        String::from("Move left")
    }

    fn reorder_item_right(&self) -> String {
        String::from("Move right")
    }

    fn reorder_item_to_end(&self) -> String {
        String::from("Move to the end")
    }

    fn reorder_item_to_start(&self) -> String {
        String::from("Move to the start")
    }

    fn expanded_icon_tap_hint(&self) -> String {
        String::from("Collapse")
    }

    fn collapsed_icon_tap_hint(&self) -> String {
        String::from("Expand")
    }

    fn expansion_tile_expanded_hint(&self) -> String {
        String::from("double tap to collapse")
    }

    fn expansion_tile_collapsed_hint(&self) -> String {
        String::from("double tap to expand")
    }

    fn expansion_tile_expanded_tap_hint(&self) -> String {
        String::from("Collapse")
    }

    fn expansion_tile_collapsed_tap_hint(&self) -> String {
        String::from("Expand for more details")
    }

    fn expanded_hint(&self) -> String {
        String::from("Collapsed")
    }

    fn collapsed_hint(&self) -> String {
        String::from("Expanded")
    }

    fn refresh_indicator_semantic_label(&self) -> String {
        String::from("Refresh")
    }

    fn remaining_text_field_character_count(&self, remaining: i32) -> String {
        match remaining {
            0 => String::from("No characters remaining"),
            1 => String::from("1 character remaining"),
            _ => format!("{remaining} characters remaining"),
        }
    }

    fn keyboard_key_alt(&self) -> String {
        String::from("Alt")
    }

    fn keyboard_key_alt_graph(&self) -> String {
        String::from("AltGr")
    }

    fn keyboard_key_backspace(&self) -> String {
        String::from("Backspace")
    }

    fn keyboard_key_caps_lock(&self) -> String {
        String::from("Caps Lock")
    }

    fn keyboard_key_channel_down(&self) -> String {
        String::from("Channel Down")
    }

    fn keyboard_key_channel_up(&self) -> String {
        String::from("Channel Up")
    }

    fn keyboard_key_control(&self) -> String {
        String::from("Ctrl")
    }

    fn keyboard_key_delete(&self) -> String {
        String::from("Del")
    }

    fn keyboard_key_eject(&self) -> String {
        String::from("Eject")
    }

    fn keyboard_key_end(&self) -> String {
        String::from("End")
    }

    fn keyboard_key_escape(&self) -> String {
        String::from("Esc")
    }

    fn keyboard_key_fn(&self) -> String {
        String::from("Fn")
    }

    fn keyboard_key_home(&self) -> String {
        String::from("Home")
    }

    fn keyboard_key_insert(&self) -> String {
        String::from("Insert")
    }

    fn keyboard_key_meta(&self) -> String {
        String::from("Meta")
    }

    fn keyboard_key_meta_mac_os(&self) -> String {
        String::from("Command")
    }

    fn keyboard_key_meta_windows(&self) -> String {
        String::from("Win")
    }

    fn keyboard_key_num_lock(&self) -> String {
        String::from("Num Lock")
    }

    fn keyboard_key_numpad1(&self) -> String {
        String::from("Num 1")
    }

    fn keyboard_key_numpad2(&self) -> String {
        String::from("Num 2")
    }

    fn keyboard_key_numpad3(&self) -> String {
        String::from("Num 3")
    }

    fn keyboard_key_numpad4(&self) -> String {
        String::from("Num 4")
    }

    fn keyboard_key_numpad5(&self) -> String {
        String::from("Num 5")
    }

    fn keyboard_key_numpad6(&self) -> String {
        String::from("Num 6")
    }

    fn keyboard_key_numpad7(&self) -> String {
        String::from("Num 7")
    }

    fn keyboard_key_numpad8(&self) -> String {
        String::from("Num 8")
    }

    fn keyboard_key_numpad9(&self) -> String {
        String::from("Num 9")
    }

    fn keyboard_key_numpad0(&self) -> String {
        String::from("Num 0")
    }

    fn keyboard_key_numpad_add(&self) -> String {
        String::from("Num +")
    }

    fn keyboard_key_numpad_comma(&self) -> String {
        String::from("Num ,")
    }

    fn keyboard_key_numpad_decimal(&self) -> String {
        String::from("Num .")
    }

    fn keyboard_key_numpad_divide(&self) -> String {
        String::from("Num /")
    }

    fn keyboard_key_numpad_enter(&self) -> String {
        String::from("Num Enter")
    }

    fn keyboard_key_numpad_equal(&self) -> String {
        String::from("Num =")
    }

    fn keyboard_key_numpad_multiply(&self) -> String {
        String::from("Num *")
    }

    fn keyboard_key_numpad_paren_left(&self) -> String {
        String::from("Num (")
    }

    fn keyboard_key_numpad_paren_right(&self) -> String {
        String::from("Num )")
    }

    fn keyboard_key_numpad_subtract(&self) -> String {
        String::from("Num -")
    }

    fn keyboard_key_page_down(&self) -> String {
        String::from("PgDown")
    }

    fn keyboard_key_page_up(&self) -> String {
        String::from("PgUp")
    }

    fn keyboard_key_power(&self) -> String {
        String::from("Power")
    }

    fn keyboard_key_power_off(&self) -> String {
        String::from("Power Off")
    }

    fn keyboard_key_print_screen(&self) -> String {
        String::from("Print Screen")
    }

    fn keyboard_key_scroll_lock(&self) -> String {
        String::from("Scroll Lock")
    }

    fn keyboard_key_select(&self) -> String {
        String::from("Select")
    }

    fn keyboard_key_shift(&self) -> String {
        String::from("Shift")
    }

    fn keyboard_key_space(&self) -> String {
        String::from("Space")
    }
}

#[cfg(test)]
pub(crate) mod tests {
    use std::cell::RefCell;
    use waft_widgets::testing::test_widgets;

    use waft_widgets::{Builder, DefaultWidgetsLocalizations, IntoWidget, SizedBox, WidgetRef};

    use waft_foundation::AppCell;

    use super::*;

    /// `child` under the US English widgets and Material localizations, as `MaterialApp`
    /// provides them.
    pub(crate) fn us_english<K>(child: impl IntoWidget<K>) -> WidgetRef {
        Localizations::new(
            Locale::new("en").country_code("US"),
            vec![
                DefaultWidgetsLocalizations::delegate(),
                DefaultMaterialLocalizations::delegate(),
            ],
        )
        .child(child)
        .into_widget()
    }

    // localizations_test.dart 'English translations exist for all MaterialLocalizations
    // properties', with the strings themselves.
    #[test]
    #[allow(deprecated)]
    fn the_default_strings_are_the_us_english_ones() {
        let strings: &dyn MaterialLocalizations = &DefaultMaterialLocalizations::new();

        assert_eq!(strings.script_category(), ScriptCategory::EnglishLike);
        assert_eq!(strings.date_separator(), "/");
        assert_eq!(strings.date_help_text(), "mm/dd/yyyy");
        assert_eq!(strings.select_year_semantics_label(), "Select year");
        assert_eq!(strings.unspecified_date(), "Date");
        assert_eq!(strings.unspecified_date_range(), "Date Range");
        assert_eq!(strings.date_input_label(), "Enter Date");
        assert_eq!(strings.date_range_start_label(), "Start Date");
        assert_eq!(strings.date_range_end_label(), "End Date");
        assert_eq!(strings.invalid_date_format_label(), "Invalid format.");
        assert_eq!(strings.invalid_date_range_label(), "Invalid range.");
        assert_eq!(strings.date_out_of_range_label(), "Out of range.");
        assert_eq!(strings.save_button_label(), "Save");
        assert_eq!(strings.date_picker_help_text(), "Select date");
        assert_eq!(strings.date_range_picker_help_text(), "Select range");
        assert_eq!(strings.calendar_mode_button_label(), "Switch to calendar");
        assert_eq!(strings.input_date_mode_button_label(), "Switch to input");
        assert_eq!(strings.time_picker_dial_help_text(), "Select time");
        assert_eq!(strings.time_picker_input_help_text(), "Enter time");
        assert_eq!(strings.time_picker_hour_label(), "Hour");
        assert_eq!(strings.time_picker_minute_label(), "Minute");
        assert_eq!(strings.invalid_time_label(), "Enter a valid time");
        assert_eq!(
            strings.dial_mode_button_label(),
            "Switch to dial picker mode"
        );
        assert_eq!(
            strings.input_time_mode_button_label(),
            "Switch to text input mode"
        );
        assert_eq!(strings.open_app_drawer_tooltip(), "Open navigation menu");
        assert_eq!(strings.back_button_tooltip(), "Back");
        assert_eq!(strings.clear_button_tooltip(), "Clear text");
        assert_eq!(strings.close_button_tooltip(), "Close");
        assert_eq!(strings.delete_button_tooltip(), "Delete");
        assert_eq!(strings.more_button_tooltip(), "More");
        assert_eq!(strings.next_month_tooltip(), "Next month");
        assert_eq!(strings.previous_month_tooltip(), "Previous month");
        assert_eq!(strings.next_page_tooltip(), "Next page");
        assert_eq!(strings.previous_page_tooltip(), "Previous page");
        assert_eq!(strings.first_page_tooltip(), "First page");
        assert_eq!(strings.last_page_tooltip(), "Last page");
        assert_eq!(strings.show_menu_tooltip(), "Show menu");
        assert_eq!(strings.drawer_label(), "Navigation menu");
        assert_eq!(strings.menu_bar_menu_label(), "Menu bar menu");
        assert_eq!(strings.popup_menu_label(), "Popup menu");
        assert_eq!(strings.dialog_label(), "Dialog");
        assert_eq!(strings.alert_dialog_label(), "Alert");
        assert_eq!(strings.search_field_label(), "Search");
        assert_eq!(strings.current_date_label(), "Today");
        assert_eq!(strings.selected_date_label(), "Selected");
        assert_eq!(strings.scrim_label(), "Scrim");
        assert_eq!(strings.bottom_sheet_label(), "Bottom Sheet");
        assert_eq!(strings.licenses_page_title(), "Licenses");
        assert_eq!(strings.rows_per_page_title(), "Rows per page:");
        assert_eq!(strings.cancel_button_label(), "Cancel");
        assert_eq!(strings.close_button_label(), "Close");
        assert_eq!(strings.continue_button_label(), "Continue");
        assert_eq!(strings.copy_button_label(), "Copy");
        assert_eq!(strings.cut_button_label(), "Cut");
        assert_eq!(strings.scan_text_button_label(), "Scan text");
        assert_eq!(strings.ok_button_label(), "OK");
        assert_eq!(strings.paste_button_label(), "Paste");
        assert_eq!(strings.select_all_button_label(), "Select all");
        assert_eq!(strings.look_up_button_label(), "Look Up");
        assert_eq!(strings.search_web_button_label(), "Search Web");
        assert_eq!(strings.share_button_label(), "Share");
        assert_eq!(strings.view_licenses_button_label(), "View licenses");
        assert_eq!(strings.ante_meridiem_abbreviation(), "AM");
        assert_eq!(strings.post_meridiem_abbreviation(), "PM");
        assert_eq!(strings.time_picker_hour_mode_announcement(), "Select hours");
        assert_eq!(
            strings.time_picker_minute_mode_announcement(),
            "Select minutes"
        );
        assert_eq!(strings.modal_barrier_dismiss_label(), "Dismiss");
        assert_eq!(strings.menu_dismiss_label(), "Dismiss menu");
        assert_eq!(strings.signed_in_label(), "Signed in");
        assert_eq!(strings.hide_accounts_label(), "Hide accounts");
        assert_eq!(strings.show_accounts_label(), "Show accounts");
        assert_eq!(strings.reorder_item_up(), "Move up");
        assert_eq!(strings.reorder_item_down(), "Move down");
        assert_eq!(strings.reorder_item_left(), "Move left");
        assert_eq!(strings.reorder_item_right(), "Move right");
        assert_eq!(strings.reorder_item_to_end(), "Move to the end");
        assert_eq!(strings.reorder_item_to_start(), "Move to the start");
        assert_eq!(strings.expanded_icon_tap_hint(), "Collapse");
        assert_eq!(strings.collapsed_icon_tap_hint(), "Expand");
        assert_eq!(
            strings.expansion_tile_expanded_hint(),
            "double tap to collapse"
        );
        assert_eq!(
            strings.expansion_tile_collapsed_hint(),
            "double tap to expand"
        );
        assert_eq!(strings.expansion_tile_expanded_tap_hint(), "Collapse");
        assert_eq!(
            strings.expansion_tile_collapsed_tap_hint(),
            "Expand for more details"
        );
        assert_eq!(strings.expanded_hint(), "Collapsed");
        assert_eq!(strings.collapsed_hint(), "Expanded");
        assert_eq!(strings.refresh_indicator_semantic_label(), "Refresh");
        assert_eq!(strings.keyboard_key_alt(), "Alt");
        assert_eq!(strings.keyboard_key_alt_graph(), "AltGr");
        assert_eq!(strings.keyboard_key_backspace(), "Backspace");
        assert_eq!(strings.keyboard_key_caps_lock(), "Caps Lock");
        assert_eq!(strings.keyboard_key_channel_down(), "Channel Down");
        assert_eq!(strings.keyboard_key_channel_up(), "Channel Up");
        assert_eq!(strings.keyboard_key_control(), "Ctrl");
        assert_eq!(strings.keyboard_key_delete(), "Del");
        assert_eq!(strings.keyboard_key_eject(), "Eject");
        assert_eq!(strings.keyboard_key_end(), "End");
        assert_eq!(strings.keyboard_key_escape(), "Esc");
        assert_eq!(strings.keyboard_key_fn(), "Fn");
        assert_eq!(strings.keyboard_key_home(), "Home");
        assert_eq!(strings.keyboard_key_insert(), "Insert");
        assert_eq!(strings.keyboard_key_meta(), "Meta");
        assert_eq!(strings.keyboard_key_meta_mac_os(), "Command");
        assert_eq!(strings.keyboard_key_meta_windows(), "Win");
        assert_eq!(strings.keyboard_key_num_lock(), "Num Lock");
        assert_eq!(strings.keyboard_key_numpad1(), "Num 1");
        assert_eq!(strings.keyboard_key_numpad2(), "Num 2");
        assert_eq!(strings.keyboard_key_numpad3(), "Num 3");
        assert_eq!(strings.keyboard_key_numpad4(), "Num 4");
        assert_eq!(strings.keyboard_key_numpad5(), "Num 5");
        assert_eq!(strings.keyboard_key_numpad6(), "Num 6");
        assert_eq!(strings.keyboard_key_numpad7(), "Num 7");
        assert_eq!(strings.keyboard_key_numpad8(), "Num 8");
        assert_eq!(strings.keyboard_key_numpad9(), "Num 9");
        assert_eq!(strings.keyboard_key_numpad0(), "Num 0");
        assert_eq!(strings.keyboard_key_numpad_add(), "Num +");
        assert_eq!(strings.keyboard_key_numpad_comma(), "Num ,");
        assert_eq!(strings.keyboard_key_numpad_decimal(), "Num .");
        assert_eq!(strings.keyboard_key_numpad_divide(), "Num /");
        assert_eq!(strings.keyboard_key_numpad_enter(), "Num Enter");
        assert_eq!(strings.keyboard_key_numpad_equal(), "Num =");
        assert_eq!(strings.keyboard_key_numpad_multiply(), "Num *");
        assert_eq!(strings.keyboard_key_numpad_paren_left(), "Num (");
        assert_eq!(strings.keyboard_key_numpad_paren_right(), "Num )");
        assert_eq!(strings.keyboard_key_numpad_subtract(), "Num -");
        assert_eq!(strings.keyboard_key_page_down(), "PgDown");
        assert_eq!(strings.keyboard_key_page_up(), "PgUp");
        assert_eq!(strings.keyboard_key_power(), "Power");
        assert_eq!(strings.keyboard_key_power_off(), "Power Off");
        assert_eq!(strings.keyboard_key_print_screen(), "Print Screen");
        assert_eq!(strings.keyboard_key_scroll_lock(), "Scroll Lock");
        assert_eq!(strings.keyboard_key_select(), "Select");
        assert_eq!(strings.keyboard_key_shift(), "Shift");
        assert_eq!(strings.keyboard_key_space(), "Space");
        assert_eq!(strings.script_category(), ScriptCategory::EnglishLike);
        assert_eq!(strings.date_separator(), "/");
        assert_eq!(strings.first_day_of_week_index(), 0);
        assert_eq!(
            strings.narrow_weekdays(),
            ["S", "M", "T", "W", "T", "F", "S"]
        );
        assert_eq!(
            strings.time_of_day_format(false),
            TimeOfDayFormat::h_colon_mm_space_a
        );
        assert_eq!(
            strings.time_of_day_format(true),
            TimeOfDayFormat::HH_colon_mm
        );
    }

    // localizations_test.dart: the strings that take an argument hold it, and no Dart
    // placeholder is left in them.
    #[test]
    fn the_strings_with_arguments_fill_them_in_and_pluralize() {
        let strings = DefaultMaterialLocalizations::new();

        assert_eq!(strings.scrim_on_tap_hint("FOO"), "Close FOO");
        assert_eq!(strings.about_list_tile_title("FOO"), "About FOO");

        assert_eq!(strings.selected_row_count_title(0), "No items selected");
        assert_eq!(strings.selected_row_count_title(1), "1 item selected");
        assert_eq!(strings.selected_row_count_title(2), "2 items selected");
        assert_eq!(strings.selected_row_count_title(100), "100 items selected");

        assert_eq!(
            strings.page_rows_info_title(1, 10, 100, true),
            "1–10 of about 100"
        );
        assert_eq!(
            strings.page_rows_info_title(1, 10, 100, false),
            "1–10 of 100"
        );

        assert_eq!(strings.licenses_package_detail_text(0), "No licenses.");
        assert_eq!(strings.licenses_package_detail_text(1), "1 license.");
        assert_eq!(strings.licenses_package_detail_text(2), "2 licenses.");
        assert_eq!(strings.licenses_package_detail_text(100), "100 licenses.");

        assert_eq!(
            strings.remaining_text_field_character_count(0),
            "No characters remaining"
        );
        assert_eq!(
            strings.remaining_text_field_character_count(1),
            "1 character remaining"
        );
        assert_eq!(
            strings.remaining_text_field_character_count(5),
            "5 characters remaining"
        );

        assert_eq!(strings.tab_label(1, 2), "Tab 1 of 2");
        assert_eq!(
            strings.date_range_start_date_semantic_label("Feb 21"),
            "Start date Feb 21"
        );
        assert_eq!(
            strings.date_range_end_date_semantic_label("Feb 21"),
            "End date Feb 21"
        );
    }

    #[test]
    fn a_time_of_day_formats_in_twelve_or_twenty_four_hours() {
        let strings = DefaultMaterialLocalizations::new();
        let format = |hour, minute, always_use_24_hour_format| {
            strings.format_time_of_day(&TimeOfDay::new(hour, minute), always_use_24_hour_format)
        };

        assert_eq!(format(7, 0, false), "7:00 AM");
        assert_eq!(format(7, 0, true), "07:00");
        assert_eq!(format(0, 5, false), "12:05 AM");
        assert_eq!(format(0, 5, true), "00:05");
        assert_eq!(format(12, 0, false), "12:00 PM");
        assert_eq!(format(23, 59, false), "11:59 PM");
        assert_eq!(format(23, 59, true), "23:59");

        assert_eq!(strings.format_hour(&TimeOfDay::new(13, 0), false), "1");
        assert_eq!(strings.format_hour(&TimeOfDay::new(13, 0), true), "13");
        assert_eq!(strings.format_minute(&TimeOfDay::new(9, 5)), "05");
        assert_eq!(strings.format_minute(&TimeOfDay::new(9, 45)), "45");
    }

    // The expected values are the Dart VM's, from the Dart code of `formatDecimal`.
    #[test]
    fn format_decimal_inserts_thousands_separators() {
        let strings = DefaultMaterialLocalizations::new();

        assert_eq!(strings.format_decimal(0), "0");
        assert_eq!(strings.format_decimal(999), "999");
        assert_eq!(strings.format_decimal(-999), "-999");
        assert_eq!(strings.format_decimal(1000), "1,000");
        assert_eq!(strings.format_decimal(-1000), "-1,000");
        assert_eq!(strings.format_decimal(100000), "100,000");
        assert_eq!(strings.format_decimal(1234567), "1,234,567");
        assert_eq!(strings.format_decimal(-1234567), "-1,234,567");
        assert_eq!(
            strings.format_decimal(i64::MAX),
            "9,223,372,036,854,775,807"
        );
        assert_eq!(
            strings.format_decimal(i64::MIN),
            "--9,223,372,036,854,775,808"
        );
    }

    #[test]
    fn a_date_formats_in_us_english() {
        let cell = AppCell::new();
        let app = cell.borrow();
        let strings = DefaultMaterialLocalizations::new();
        let date = DateTime::new(&app, 2019, 2, 21);

        assert_eq!(strings.format_year(&app, &date), "2019");
        assert_eq!(strings.format_compact_date(&app, &date), "02/21/2019");
        assert_eq!(
            strings.format_compact_date(&app, &DateTime::new(&app, 5, 1, 2)),
            "01/02/0005"
        );
        assert_eq!(strings.format_short_date(&app, &date), "Feb 21, 2019");
        assert_eq!(strings.format_medium_date(&app, &date), "Thu, Feb 21");
        assert_eq!(
            strings.format_full_date(&app, &date),
            "Thursday, February 21, 2019"
        );
        assert_eq!(strings.format_month_year(&app, &date), "February 2019");
        assert_eq!(strings.format_short_month_day(&app, &date), "Feb 21");

        // The examples of the interface's documentation.
        let example = DateTime::new(&app, 2017, 9, 27);
        assert_eq!(strings.format_medium_date(&app, &example), "Wed, Sep 27");
        assert_eq!(
            strings.format_full_date(&app, &example),
            "Wednesday, September 27, 2017"
        );
    }

    // localizations_test.dart "parseCompactDate doesn't throw an exception on invalid text",
    // and the Dart VM's answers for the other strings.
    #[test]
    fn parse_compact_date_reads_a_us_date_and_rejects_the_rest() {
        let cell = AppCell::new();
        let app = cell.borrow();
        let strings = DefaultMaterialLocalizations::new();
        let parse = |text| strings.parse_compact_date(&app, Some(text));

        assert_eq!(parse("10/05/2023"), Some(DateTime::new(&app, 2023, 10, 5)));
        assert_eq!(parse("10/05/2023666777889"), None);

        assert_eq!(strings.parse_compact_date(&app, None), None);
        assert_eq!(parse("02/21/2019"), Some(DateTime::new(&app, 2019, 2, 21)));
        assert_eq!(
            parse(" 02/ 21/+2019"),
            Some(DateTime::new(&app, 2019, 2, 21))
        );
        assert_eq!(parse("1/1/1"), Some(DateTime::new(&app, 1, 1, 1)));
        assert_eq!(parse("02/21"), None);
        assert_eq!(parse("a/b/c"), None);
        assert_eq!(parse("0x1/01/2019"), None);
        assert_eq!(parse("13/01/2019"), None);
        assert_eq!(parse("01/01/0"), None);
        assert_eq!(parse("02/29/2019"), None);
        assert_eq!(parse("02/29/2020"), Some(DateTime::new(&app, 2020, 2, 29)));
        assert_eq!(parse("02/29/1900"), None);
        assert_eq!(parse("02/29/2000"), Some(DateTime::new(&app, 2000, 2, 29)));
        // The last day a `DateTime` holds is a valid local date only east of UTC, where its
        // midnight comes before the last instant.
        let last = DateTime::from_milliseconds_since_epoch(8_640_000_000_000_000, false);
        let last_day = (last.day(&app) == 13).then(|| DateTime::new(&app, 275760, 9, 13));
        assert_eq!(parse("09/13/275760"), last_day);
        assert_eq!(parse("09/14/275760"), None);
    }

    #[test]
    fn the_delegate_supports_english_only_and_prints_as_dart_does() {
        let delegate = DefaultMaterialLocalizations::delegate();
        assert!(delegate.is_supported(&Locale::new("en").country_code("GB")));
        assert!(!delegate.is_supported(&Locale::new("fr")));
        assert_eq!(
            format!("{delegate:?}"),
            "DefaultMaterialLocalizations.delegate(en_US)"
        );
    }

    #[test]
    fn load_completes_synchronously() {
        let strings = DefaultMaterialLocalizations::load(&Locale::new("en"));
        assert!(strings.is_completed(), "Dart's SynchronousFuture");
        assert_eq!(
            strings.peek().expect("complete").back_button_tooltip(),
            "Back"
        );
    }

    // localizations_test.dart 'MaterialLocalizations.of throws', the context with
    // localizations.
    #[test]
    fn of_finds_the_strings_through_a_localizations_ancestor() {
        test_widgets(|tester| {
            let seen = Rc::new(RefCell::new(None));
            let probe = Builder::new({
                let seen = Rc::clone(&seen);
                move |app, context| {
                    *seen.borrow_mut() =
                        Some(<dyn MaterialLocalizations>::of(app, context).back_button_tooltip());
                    SizedBox::shrink().into_widget()
                }
            });
            tester.pump_widget(us_english(probe));
            assert_eq!(seen.borrow().as_deref(), Some("Back"));
        });
    }

    // localizations_test.dart 'MaterialLocalizations.of throws', the context without
    // localizations.
    #[test]
    #[should_panic(expected = "No MaterialLocalizations found")]
    fn of_panics_without_a_localizations_ancestor() {
        test_widgets(|tester| {
            let probe = Builder::new(|app, context| {
                <dyn MaterialLocalizations>::of(app, context);
                SizedBox::shrink().into_widget()
            });
            tester.pump_widget(probe.into_widget());
        });
    }
}