waft-material 0.16.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
//! Flutter counterpart: material_ui's `text_theme.dart`.

use waft_embedder::{Color, FontFeature, FontVariation, TextDecoration, TextDecorationStyle};
use waft_foundation::{App, DiagnosticsProperty};
use waft_painting::TextStyle;
use waft_widgets::BuildContext;

use crate::theme::Theme;

/// Material design text theme.
///
/// Definitions for the various typographical styles found in Material Design
/// (e.g., label_large, body_small). Rather than creating a [`TextTheme`] directly,
/// you can obtain an instance as `Typography.black` or `Typography.white`.
///
/// To obtain the current text theme, call [`TextTheme::of`] with the current
/// `BuildContext`. This is equivalent to calling `Theme::of` and reading
/// the `ThemeData.text_theme` property.
///
/// The names of the TextTheme properties match this table from the
/// [Material Design spec](https://m3.material.io/styles/typography/tokens).
///
/// ![](https://lh3.googleusercontent.com/Yvngs5mQSjXa_9T4X3JDucO62c5hdZHPDa7qeRH6DsJQvGr_q7EBrTkhkPiQd9OeR1v_Uk38Cjd9nUpP3nevDyHpKWuXSfQ1Gq78bOnBN7sr=s0)
///
/// The Material Design typography scheme was significantly changed in the
/// current (2021) version of the specification
/// ([https://m3.material.io/styles/typography/tokens](https://m3.material.io/styles/typography/tokens)).
///
/// The **2021** spec has fifteen text styles:
///
/// | NAME           | SIZE |  HEIGHT |  WEIGHT |  SPACING |             |
/// |----------------|------|---------|---------|----------|-------------|
/// | displayLarge   | 57.0 |   64.0  | regular | -0.25    |             |
/// | displayMedium  | 45.0 |   52.0  | regular |  0.0     |             |
/// | displaySmall   | 36.0 |   44.0  | regular |  0.0     |             |
/// | headlineLarge  | 32.0 |   40.0  | regular |  0.0     |             |
/// | headlineMedium | 28.0 |   36.0  | regular |  0.0     |             |
/// | headlineSmall  | 24.0 |   32.0  | regular |  0.0     |             |
/// | titleLarge     | 22.0 |   28.0  | regular |  0.0     |             |
/// | titleMedium    | 16.0 |   24.0  | medium  |  0.15    |             |
/// | titleSmall     | 14.0 |   20.0  | medium  |  0.1     |             |
/// | bodyLarge      | 16.0 |   24.0  | regular |  0.5     |             |
/// | bodyMedium     | 14.0 |   20.0  | regular |  0.25    |             |
/// | bodySmall      | 12.0 |   16.0  | regular |  0.4     |             |
/// | labelLarge     | 14.0 |   20.0  | medium  |  0.1     |             |
/// | labelMedium    | 12.0 |   16.0  | medium  |  0.5     |             |
/// | labelSmall     | 11.0 |   16.0  | medium  |  0.5     |             |
///
/// ...where "regular" is `FontWeight.w400` and "medium" is `FontWeight.w500`.
///
/// The names of the 2018 TextTheme properties match this table from the
/// [Material Design spec](https://material.io/design/typography/the-type-system.html#type-scale)
/// with a few exceptions: the styles called H1-H6 in the spec are
/// displayLarge-titleLarge in the API chart, body1,body2 are called
/// bodyLarge and bodyMedium, caption is now bodySmall, button is labelLarge,
/// and overline is now labelSmall.
///
/// The **2018** spec has thirteen text styles:
///
/// | NAME           | SIZE |  WEIGHT |  SPACING |             |
/// |----------------|------|---------|----------|-------------|
/// | displayLarge   | 96.0 | light   | -1.5     |             |
/// | displayMedium  | 60.0 | light   | -0.5     |             |
/// | displaySmall   | 48.0 | regular |  0.0     |             |
/// | headlineMedium | 34.0 | regular |  0.25    |             |
/// | headlineSmall  | 24.0 | regular |  0.0     |             |
/// | titleLarge     | 20.0 | medium  |  0.15    |             |
/// | titleMedium    | 16.0 | regular |  0.15    |             |
/// | titleSmall     | 14.0 | medium  |  0.1     |             |
/// | bodyLarge      | 16.0 | regular |  0.5     |             |
/// | bodyMedium     | 14.0 | regular |  0.25    |             |
/// | bodySmall      | 12.0 | regular |  0.4     |             |
/// | labelLarge     | 14.0 | medium  |  1.25    |             |
/// | labelSmall     | 10.0 | regular |  1.5     |             |
///
/// ...where "light" is `FontWeight.w300`, "regular" is `FontWeight.w400` and
/// "medium" is `FontWeight.w500`.
///
/// By default, text styles are initialized to match the 2018 Material Design
/// specification as listed above. To provide backwards compatibility, the 2014
/// specification is also available.
///
/// To explicitly configure a `Theme` for the 2018 sizes, weights, and letter
/// spacings, you can initialize its `ThemeData.typography` value using
/// `Typography.material2018`. The `Typography` constructor defaults to this
/// configuration. To configure a `Theme` for the 2014 sizes, weights, and letter
/// spacings, initialize its `ThemeData.typography` value using
/// `Typography.material2014`.
///
/// See also:
///
///  * `Typography`, the class that generates [`TextTheme`]s appropriate for a platform.
///  * `Theme`, for other aspects of a Material Design application that can be
///    globally adjusted, such as the color scheme.
///  * <https://material.io/design/typography/>
#[derive(Clone, Debug, Default, PartialEq)]
pub struct TextTheme {
    /// Largest of the display styles.
    ///
    /// As the largest text on the screen, display styles are reserved for short,
    /// important text or numerals. They work best on large screens.
    pub display_large: Option<TextStyle>,
    /// Middle size of the display styles.
    ///
    /// As the largest text on the screen, display styles are reserved for short,
    /// important text or numerals. They work best on large screens.
    pub display_medium: Option<TextStyle>,
    /// Smallest of the display styles.
    ///
    /// As the largest text on the screen, display styles are reserved for short,
    /// important text or numerals. They work best on large screens.
    pub display_small: Option<TextStyle>,
    /// Largest of the headline styles.
    ///
    /// Headline styles are smaller than display styles. They're best-suited for
    /// short, high-emphasis text on smaller screens.
    pub headline_large: Option<TextStyle>,
    /// Middle size of the headline styles.
    ///
    /// Headline styles are smaller than display styles. They're best-suited for
    /// short, high-emphasis text on smaller screens.
    pub headline_medium: Option<TextStyle>,
    /// Smallest of the headline styles.
    ///
    /// Headline styles are smaller than display styles. They're best-suited for
    /// short, high-emphasis text on smaller screens.
    pub headline_small: Option<TextStyle>,
    /// Largest of the title styles.
    ///
    /// Titles are smaller than headline styles and should be used for shorter,
    /// medium-emphasis text.
    pub title_large: Option<TextStyle>,
    /// Middle size of the title styles.
    ///
    /// Titles are smaller than headline styles and should be used for shorter,
    /// medium-emphasis text.
    pub title_medium: Option<TextStyle>,
    /// Smallest of the title styles.
    ///
    /// Titles are smaller than headline styles and should be used for shorter,
    /// medium-emphasis text.
    pub title_small: Option<TextStyle>,
    /// Largest of the body styles.
    ///
    /// Body styles are used for longer passages of text.
    pub body_large: Option<TextStyle>,
    /// Middle size of the body styles.
    ///
    /// Body styles are used for longer passages of text.
    ///
    /// The default text style for `Material`.
    pub body_medium: Option<TextStyle>,
    /// Smallest of the body styles.
    ///
    /// Body styles are used for longer passages of text.
    pub body_small: Option<TextStyle>,
    /// Largest of the label styles.
    ///
    /// Label styles are smaller, utilitarian styles, used for areas of the UI
    /// such as text inside of components or very small supporting text in the
    /// content body, like captions.
    ///
    /// Used for text on `ElevatedButton`, `TextButton` and `OutlinedButton`.
    pub label_large: Option<TextStyle>,
    /// Middle size of the label styles.
    ///
    /// Label styles are smaller, utilitarian styles, used for areas of the UI
    /// such as text inside of components or very small supporting text in the
    /// content body, like captions.
    pub label_medium: Option<TextStyle>,
    /// Smallest of the label styles.
    ///
    /// Label styles are smaller, utilitarian styles, used for areas of the UI
    /// such as text inside of components or very small supporting text in the
    /// content body, like captions.
    pub label_small: Option<TextStyle>,
}

impl TextTheme {
    /// Creates a text theme that uses the given values.
    ///
    /// Rather than creating a new text theme, consider using `Typography.black`
    /// or `Typography.white`, which implement the typography styles in the
    /// Material Design specification:
    ///
    /// <https://material.io/design/typography/#type-scale>
    ///
    /// If you do decide to create your own text theme, consider using one of
    /// those predefined themes as a starting point for [`copy_with`](Self::copy_with) or
    /// [`apply`](Self::apply).
    ///
    /// The 2018 styles cannot be mixed with the 2021 styles. Only one or the
    /// other is allowed in this constructor. The 2018 styles are deprecated and
    /// will eventually be removed.
    pub fn new() -> TextTheme {
        TextTheme::default()
    }

    /// Dart `TextTheme(displayLarge:)`.
    pub fn display_large(mut self, display_large: TextStyle) -> TextTheme {
        self.display_large = Some(display_large);
        self
    }

    /// Dart `TextTheme(displayMedium:)`.
    pub fn display_medium(mut self, display_medium: TextStyle) -> TextTheme {
        self.display_medium = Some(display_medium);
        self
    }

    /// Dart `TextTheme(displaySmall:)`.
    pub fn display_small(mut self, display_small: TextStyle) -> TextTheme {
        self.display_small = Some(display_small);
        self
    }

    /// Dart `TextTheme(headlineLarge:)`.
    pub fn headline_large(mut self, headline_large: TextStyle) -> TextTheme {
        self.headline_large = Some(headline_large);
        self
    }

    /// Dart `TextTheme(headlineMedium:)`.
    pub fn headline_medium(mut self, headline_medium: TextStyle) -> TextTheme {
        self.headline_medium = Some(headline_medium);
        self
    }

    /// Dart `TextTheme(headlineSmall:)`.
    pub fn headline_small(mut self, headline_small: TextStyle) -> TextTheme {
        self.headline_small = Some(headline_small);
        self
    }

    /// Dart `TextTheme(titleLarge:)`.
    pub fn title_large(mut self, title_large: TextStyle) -> TextTheme {
        self.title_large = Some(title_large);
        self
    }

    /// Dart `TextTheme(titleMedium:)`.
    pub fn title_medium(mut self, title_medium: TextStyle) -> TextTheme {
        self.title_medium = Some(title_medium);
        self
    }

    /// Dart `TextTheme(titleSmall:)`.
    pub fn title_small(mut self, title_small: TextStyle) -> TextTheme {
        self.title_small = Some(title_small);
        self
    }

    /// Dart `TextTheme(bodyLarge:)`.
    pub fn body_large(mut self, body_large: TextStyle) -> TextTheme {
        self.body_large = Some(body_large);
        self
    }

    /// Dart `TextTheme(bodyMedium:)`.
    pub fn body_medium(mut self, body_medium: TextStyle) -> TextTheme {
        self.body_medium = Some(body_medium);
        self
    }

    /// Dart `TextTheme(bodySmall:)`.
    pub fn body_small(mut self, body_small: TextStyle) -> TextTheme {
        self.body_small = Some(body_small);
        self
    }

    /// Dart `TextTheme(labelLarge:)`.
    pub fn label_large(mut self, label_large: TextStyle) -> TextTheme {
        self.label_large = Some(label_large);
        self
    }

    /// Dart `TextTheme(labelMedium:)`.
    pub fn label_medium(mut self, label_medium: TextStyle) -> TextTheme {
        self.label_medium = Some(label_medium);
        self
    }

    /// Dart `TextTheme(labelSmall:)`.
    pub fn label_small(mut self, label_small: TextStyle) -> TextTheme {
        self.label_small = Some(label_small);
        self
    }

    /// Creates a copy of this text theme but with the given fields replaced with
    /// the new values.
    ///
    /// Consider using `Typography.black` or `Typography.white`, which implement
    /// the typography styles in the Material Design specification, as a starting
    /// point.
    ///
    /// Dart's named arguments are the setters on the copy:
    /// `theme.copy_with().title_large(style)`.
    ///
    /// See also:
    ///
    ///  * [`merge`](Self::merge) is used instead of [`copy_with`](Self::copy_with) when you
    ///    want to merge all of the fields of a TextTheme instead of individual fields.
    pub fn copy_with(&self) -> TextTheme {
        self.clone()
    }

    /// Creates a new [`TextTheme`] where each text style from this object has been
    /// merged with the matching text style from the `other` object.
    ///
    /// The merging is done by calling [`TextStyle::merge`] on each respective pair
    /// of text styles from this and the `other` text themes and is subject to
    /// the value of [`TextStyle::inherit`] flag. For more details, see the
    /// documentation on [`TextStyle::merge`] and [`TextStyle::inherit`].
    ///
    /// If this theme, or the `other` theme has members that are null, then the
    /// non-null one (if any) is used. If the `other` theme is itself null, then
    /// this [`TextTheme`] is returned unchanged. If values in both are set, then
    /// the values are merged using [`TextStyle::merge`].
    ///
    /// This is particularly useful if one [`TextTheme`] defines one set of
    /// properties and another defines a different set, e.g. having colors
    /// defined in one text theme and font sizes in another, or when one
    /// [`TextTheme`] has only some fields defined, and you want to define the rest
    /// by merging it with a default theme.
    ///
    /// See also:
    ///
    ///  * [`copy_with`](Self::copy_with) is used instead of [`merge`](Self::merge) when you
    ///    wish to override individual fields in the [`TextTheme`] instead of merging all of
    ///    the fields of two [`TextTheme`]s.
    pub fn merge(&self, other: Option<&TextTheme>) -> TextTheme {
        let Some(other) = other else {
            return self.clone();
        };

        fn merge_styles(
            style: &Option<TextStyle>,
            other_style: &Option<TextStyle>,
        ) -> Option<TextStyle> {
            match style {
                Some(style) => Some(style.merge(other_style.as_ref())),
                None => other_style.clone(),
            }
        }

        TextTheme {
            display_large: merge_styles(&self.display_large, &other.display_large),
            display_medium: merge_styles(&self.display_medium, &other.display_medium),
            display_small: merge_styles(&self.display_small, &other.display_small),
            headline_large: merge_styles(&self.headline_large, &other.headline_large),
            headline_medium: merge_styles(&self.headline_medium, &other.headline_medium),
            headline_small: merge_styles(&self.headline_small, &other.headline_small),
            title_large: merge_styles(&self.title_large, &other.title_large),
            title_medium: merge_styles(&self.title_medium, &other.title_medium),
            title_small: merge_styles(&self.title_small, &other.title_small),
            body_large: merge_styles(&self.body_large, &other.body_large),
            body_medium: merge_styles(&self.body_medium, &other.body_medium),
            body_small: merge_styles(&self.body_small, &other.body_small),
            label_large: merge_styles(&self.label_large, &other.label_large),
            label_medium: merge_styles(&self.label_medium, &other.label_medium),
            label_small: merge_styles(&self.label_small, &other.label_small),
        }
    }

    /// Creates a copy of this text theme but with the given field replaced in
    /// each of the individual text styles.
    ///
    /// The `display_color` is applied to [`display_large`](Self::display_large),
    /// [`display_medium`](Self::display_medium), [`display_small`](Self::display_small),
    /// [`headline_large`](Self::headline_large), [`headline_medium`](Self::headline_medium),
    /// and [`body_small`](Self::body_small). The `body_color` is applied to the remaining
    /// text styles.
    ///
    /// Consider using `Typography.black` or `Typography.white`, which implement
    /// the typography styles in the Material Design specification, as a starting
    /// point.
    ///
    /// Chain the named arguments, then [`TextThemeApply::into_text_theme`];
    /// `theme.apply()` with no further setters is Dart `apply()` with defaults.
    pub fn apply(&self) -> TextThemeApply<'_> {
        TextThemeApply::new(self)
    }

    /// Linearly interpolate between two text themes.
    ///
    /// {@macro dart.ui.shadow.lerp}
    pub fn lerp(a: Option<&TextTheme>, b: Option<&TextTheme>, t: f64) -> TextTheme {
        if let (Some(a), Some(b)) = (a, b)
            && std::ptr::eq(a, b)
        {
            return a.clone();
        }
        let lerp = |style: fn(&TextTheme) -> Option<&TextStyle>| {
            TextStyle::lerp(a.and_then(style), b.and_then(style), t)
        };
        TextTheme {
            display_large: lerp(|theme| theme.display_large.as_ref()),
            display_medium: lerp(|theme| theme.display_medium.as_ref()),
            display_small: lerp(|theme| theme.display_small.as_ref()),
            headline_large: lerp(|theme| theme.headline_large.as_ref()),
            headline_medium: lerp(|theme| theme.headline_medium.as_ref()),
            headline_small: lerp(|theme| theme.headline_small.as_ref()),
            title_large: lerp(|theme| theme.title_large.as_ref()),
            title_medium: lerp(|theme| theme.title_medium.as_ref()),
            title_small: lerp(|theme| theme.title_small.as_ref()),
            body_large: lerp(|theme| theme.body_large.as_ref()),
            body_medium: lerp(|theme| theme.body_medium.as_ref()),
            body_small: lerp(|theme| theme.body_small.as_ref()),
            label_large: lerp(|theme| theme.label_large.as_ref()),
            label_medium: lerp(|theme| theme.label_medium.as_ref()),
            label_small: lerp(|theme| theme.label_small.as_ref()),
        }
    }

    /// The `ThemeData.text_theme` property of the ambient `Theme`.
    ///
    /// Equivalent to `Theme::of(app, context).text_theme`.
    ///
    /// See also:
    /// * [`TextTheme::primary_of`], which returns the `ThemeData.primary_text_theme` property
    ///   of the ambient `Theme` instead.
    pub fn of(app: &mut App, context: BuildContext) -> TextTheme {
        Theme::of(app, context).text_theme.clone()
    }

    /// The `ThemeData.primary_text_theme` property of the ambient `Theme`.
    ///
    ///
    /// Equivalent to `Theme::of(app, context).primary_text_theme`.
    ///
    /// See also:
    /// * [`TextTheme::of`], which returns the `ThemeData.text_theme` property of the ambient
    ///   `Theme` instead.
    pub fn primary_of(app: &mut App, context: BuildContext) -> TextTheme {
        Theme::of(app, context).primary_text_theme.clone()
    }
}

/// Dart `TextTheme.apply` named optionals.
pub struct TextThemeApply<'a> {
    theme: &'a TextTheme,
    font_family: Option<String>,
    font_family_fallback: Option<Vec<String>>,
    package: Option<String>,
    font_size_factor: f64,
    font_size_delta: f64,
    letter_spacing_factor: f64,
    letter_spacing_delta: f64,
    word_spacing_factor: f64,
    word_spacing_delta: f64,
    height_factor: f64,
    height_delta: f64,
    display_color: Option<Color>,
    body_color: Option<Color>,
    decoration: Option<TextDecoration>,
    decoration_color: Option<Color>,
    decoration_style: Option<TextDecorationStyle>,
    font_features: Option<Vec<FontFeature>>,
    font_variations: Option<Vec<FontVariation>>,
}

impl<'a> TextThemeApply<'a> {
    fn new(theme: &'a TextTheme) -> TextThemeApply<'a> {
        TextThemeApply {
            theme,
            font_family: None,
            font_family_fallback: None,
            package: None,
            font_size_factor: 1.0,
            font_size_delta: 0.0,
            letter_spacing_factor: 1.0,
            letter_spacing_delta: 0.0,
            word_spacing_factor: 1.0,
            word_spacing_delta: 0.0,
            height_factor: 1.0,
            height_delta: 0.0,
            display_color: None,
            body_color: None,
            decoration: None,
            decoration_color: None,
            decoration_style: None,
            font_features: None,
            font_variations: None,
        }
    }

    /// Dart `apply(fontFamily:)`.
    pub fn font_family(mut self, font_family: impl Into<String>) -> TextThemeApply<'a> {
        self.font_family = Some(font_family.into());
        self
    }

    /// Dart `apply(fontFamilyFallback:)`.
    pub fn font_family_fallback(mut self, font_family_fallback: Vec<String>) -> TextThemeApply<'a> {
        self.font_family_fallback = Some(font_family_fallback);
        self
    }

    /// Dart `apply(package:)`.
    pub fn package(mut self, package: impl Into<String>) -> TextThemeApply<'a> {
        self.package = Some(package.into());
        self
    }

    /// Dart `apply(fontSizeFactor:)`.
    pub fn font_size_factor(mut self, font_size_factor: f64) -> TextThemeApply<'a> {
        self.font_size_factor = font_size_factor;
        self
    }

    /// Dart `apply(fontSizeDelta:)`.
    pub fn font_size_delta(mut self, font_size_delta: f64) -> TextThemeApply<'a> {
        self.font_size_delta = font_size_delta;
        self
    }

    /// Dart `apply(letterSpacingFactor:)`.
    pub fn letter_spacing_factor(mut self, letter_spacing_factor: f64) -> TextThemeApply<'a> {
        self.letter_spacing_factor = letter_spacing_factor;
        self
    }

    /// Dart `apply(letterSpacingDelta:)`.
    pub fn letter_spacing_delta(mut self, letter_spacing_delta: f64) -> TextThemeApply<'a> {
        self.letter_spacing_delta = letter_spacing_delta;
        self
    }

    /// Dart `apply(wordSpacingFactor:)`.
    pub fn word_spacing_factor(mut self, word_spacing_factor: f64) -> TextThemeApply<'a> {
        self.word_spacing_factor = word_spacing_factor;
        self
    }

    /// Dart `apply(wordSpacingDelta:)`.
    pub fn word_spacing_delta(mut self, word_spacing_delta: f64) -> TextThemeApply<'a> {
        self.word_spacing_delta = word_spacing_delta;
        self
    }

    /// Dart `apply(heightFactor:)`.
    pub fn height_factor(mut self, height_factor: f64) -> TextThemeApply<'a> {
        self.height_factor = height_factor;
        self
    }

    /// Dart `apply(heightDelta:)`.
    pub fn height_delta(mut self, height_delta: f64) -> TextThemeApply<'a> {
        self.height_delta = height_delta;
        self
    }

    /// Dart `apply(displayColor:)`.
    pub fn display_color(mut self, display_color: Color) -> TextThemeApply<'a> {
        self.display_color = Some(display_color);
        self
    }

    /// Dart `apply(bodyColor:)`.
    pub fn body_color(mut self, body_color: Color) -> TextThemeApply<'a> {
        self.body_color = Some(body_color);
        self
    }

    /// Dart `apply(decoration:)`.
    pub fn decoration(mut self, decoration: TextDecoration) -> TextThemeApply<'a> {
        self.decoration = Some(decoration);
        self
    }

    /// Dart `apply(decorationColor:)`.
    pub fn decoration_color(mut self, decoration_color: Color) -> TextThemeApply<'a> {
        self.decoration_color = Some(decoration_color);
        self
    }

    /// Dart `apply(decorationStyle:)`.
    pub fn decoration_style(mut self, decoration_style: TextDecorationStyle) -> TextThemeApply<'a> {
        self.decoration_style = Some(decoration_style);
        self
    }

    /// Dart `apply(fontFeatures:)`.
    pub fn font_features(mut self, font_features: Vec<FontFeature>) -> TextThemeApply<'a> {
        self.font_features = Some(font_features);
        self
    }

    /// Dart `apply(fontVariations:)`.
    pub fn font_variations(mut self, font_variations: Vec<FontVariation>) -> TextThemeApply<'a> {
        self.font_variations = Some(font_variations);
        self
    }

    /// The text theme with every style applied.
    pub fn into_text_theme(self) -> TextTheme {
        let theme = self.theme;
        let display_color = self.display_color;
        let body_color = self.body_color;
        TextTheme {
            display_large: self.apply_to(theme.display_large.as_ref(), display_color),
            display_medium: self.apply_to(theme.display_medium.as_ref(), display_color),
            display_small: self.apply_to(theme.display_small.as_ref(), display_color),
            headline_large: self.apply_to(theme.headline_large.as_ref(), display_color),
            headline_medium: self.apply_to(theme.headline_medium.as_ref(), display_color),
            headline_small: self.apply_to(theme.headline_small.as_ref(), body_color),
            title_large: self.apply_to(theme.title_large.as_ref(), body_color),
            title_medium: self.apply_to(theme.title_medium.as_ref(), body_color),
            title_small: self.apply_to(theme.title_small.as_ref(), body_color),
            body_large: self.apply_to(theme.body_large.as_ref(), body_color),
            body_medium: self.apply_to(theme.body_medium.as_ref(), body_color),
            body_small: self.apply_to(theme.body_small.as_ref(), display_color),
            label_large: self.apply_to(theme.label_large.as_ref(), body_color),
            label_medium: self.apply_to(theme.label_medium.as_ref(), body_color),
            label_small: self.apply_to(theme.label_small.as_ref(), body_color),
        }
    }

    /// Dart's local `applyTo`.
    fn apply_to(&self, style: Option<&TextStyle>, color: Option<Color>) -> Option<TextStyle> {
        let mut apply = style?
            .apply()
            .font_size_factor(self.font_size_factor)
            .font_size_delta(self.font_size_delta)
            .letter_spacing_delta(self.letter_spacing_delta)
            .letter_spacing_factor(self.letter_spacing_factor)
            .word_spacing_delta(self.word_spacing_delta)
            .word_spacing_factor(self.word_spacing_factor)
            .height_factor(self.height_factor)
            .height_delta(self.height_delta);
        if let Some(color) = color {
            apply = apply.color(color);
        }
        if let Some(decoration) = self.decoration {
            apply = apply.decoration(decoration);
        }
        if let Some(decoration_color) = self.decoration_color {
            apply = apply.decoration_color(decoration_color);
        }
        if let Some(decoration_style) = self.decoration_style {
            apply = apply.decoration_style(decoration_style);
        }
        if let Some(font_family) = &self.font_family {
            apply = apply.font_family(font_family.clone());
        }
        if let Some(font_family_fallback) = &self.font_family_fallback {
            apply = apply.font_family_fallback(font_family_fallback.clone());
        }
        if let Some(package) = &self.package {
            apply = apply.package(package.clone());
        }
        if let Some(font_features) = &self.font_features {
            apply = apply.font_features(font_features.clone());
        }
        if let Some(font_variations) = &self.font_variations {
            apply = apply.font_variations(font_variations.clone());
        }
        Some(apply.into_style())
    }
}

impl From<TextThemeApply<'_>> for TextTheme {
    fn from(apply: TextThemeApply<'_>) -> TextTheme {
        apply.into_text_theme()
    }
}

impl waft_foundation::Diagnosticable for TextTheme {
    fn debug_fill_properties(&self, properties: &mut waft_foundation::DiagnosticPropertiesBuilder) {
        // Dart's `defaultTargetPlatform`; [`Typography::material2018`]'s default platform is
        // Android. Diagnostics on another platform compare against Android's defaults.
        let default_theme = crate::typography::Typography::material2018().build().black;
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("displayLarge", self.display_large.clone())
                .default_value(default_theme.display_large.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("displayMedium", self.display_medium.clone())
                .default_value(default_theme.display_medium.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("displaySmall", self.display_small.clone())
                .default_value(default_theme.display_small.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("headlineLarge", self.headline_large.clone())
                .default_value(default_theme.headline_large.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("headlineMedium", self.headline_medium.clone())
                .default_value(default_theme.headline_medium.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("headlineSmall", self.headline_small.clone())
                .default_value(default_theme.headline_small.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("titleLarge", self.title_large.clone())
                .default_value(default_theme.title_large.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("titleMedium", self.title_medium.clone())
                .default_value(default_theme.title_medium.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("titleSmall", self.title_small.clone())
                .default_value(default_theme.title_small.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("bodyLarge", self.body_large.clone())
                .default_value(default_theme.body_large.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("bodyMedium", self.body_medium.clone())
                .default_value(default_theme.body_medium.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("bodySmall", self.body_small.clone())
                .default_value(default_theme.body_small.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("labelLarge", self.label_large.clone())
                .default_value(default_theme.label_large.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("labelMedium", self.label_medium.clone())
                .default_value(default_theme.label_medium.clone()),
        );
        properties.add(
            DiagnosticsProperty::<TextStyle>::new("labelSmall", self.label_small.clone())
                .default_value(default_theme.label_small.clone()),
        );
    }
}

impl std::fmt::Display for TextTheme {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&waft_foundation::Diagnosticable::to_string(self))
    }
}

#[cfg(test)]
mod tests {
    use waft_embedder::{Brightness, FontStyle};
    use waft_widgets::IntoWidget;

    use waft_widgets::testing::test_widgets;

    use super::*;
    use crate::colors::Colors;
    use crate::test_support::probe;
    use crate::theme::Theme;
    use crate::theme_data::ThemeData;
    use crate::typography::Typography;

    fn styles(theme: &TextTheme) -> [&TextStyle; 15] {
        [
            &theme.display_large,
            &theme.display_medium,
            &theme.display_small,
            &theme.headline_large,
            &theme.headline_medium,
            &theme.headline_small,
            &theme.title_large,
            &theme.title_medium,
            &theme.title_small,
            &theme.body_large,
            &theme.body_medium,
            &theme.body_small,
            &theme.label_large,
            &theme.label_medium,
            &theme.label_small,
        ]
        .map(|style| style.as_ref().expect("the text theme has this style"))
    }

    fn optional_styles(theme: &TextTheme) -> [&Option<TextStyle>; 15] {
        [
            &theme.display_large,
            &theme.display_medium,
            &theme.display_small,
            &theme.headline_large,
            &theme.headline_medium,
            &theme.headline_small,
            &theme.title_large,
            &theme.title_medium,
            &theme.title_small,
            &theme.body_large,
            &theme.body_medium,
            &theme.body_small,
            &theme.label_large,
            &theme.label_medium,
            &theme.label_small,
        ]
    }

    fn color(color: Color) -> Option<waft_painting::AnyColor> {
        Some(color.into())
    }

    #[test]
    fn copy_with_apply_and_merge_of_an_empty_text_theme_are_empty() {
        assert_eq!(TextTheme::new(), TextTheme::new().copy_with());
        assert_eq!(TextTheme::new(), TextTheme::new().apply().into_text_theme());
        assert_eq!(TextTheme::new(), TextTheme::new().merge(None));
    }

    #[test]
    fn lerp_special_cases() {
        assert_eq!(TextTheme::lerp(None, None, 0.0), TextTheme::new());
        let theme = TextTheme::new();
        assert_eq!(TextTheme::lerp(Some(&theme), Some(&theme), 0.5), theme);
    }

    #[test]
    fn copy_with_apply_and_merge_of_typography_black() {
        let typography = Typography::material2018().build();
        assert_eq!(*typography.black, typography.black.copy_with());
        assert_eq!(
            *typography.black,
            typography.black.apply().into_text_theme()
        );
        assert_eq!(*typography.black, typography.black.merge(None));
        assert_eq!(
            *typography.black,
            TextTheme::new().merge(Some(&typography.black))
        );
        assert_eq!(
            *typography.black,
            typography.black.merge(Some(&typography.black))
        );
        assert_eq!(
            *typography.white,
            typography.black.merge(Some(&typography.white))
        );
        assert_ne!(typography.black, typography.white);
    }

    #[test]
    fn copy_with_replaces_every_style() {
        let typography = Typography::material2018().build();
        let white = &typography.white;
        let style = |style: &Option<TextStyle>| style.clone().expect("a style");
        let white_copy = typography
            .black
            .copy_with()
            .display_large(style(&white.display_large))
            .display_medium(style(&white.display_medium))
            .display_small(style(&white.display_small))
            .headline_large(style(&white.headline_large))
            .headline_medium(style(&white.headline_medium))
            .headline_small(style(&white.headline_small))
            .title_large(style(&white.title_large))
            .title_medium(style(&white.title_medium))
            .title_small(style(&white.title_small))
            .body_large(style(&white.body_large))
            .body_medium(style(&white.body_medium))
            .body_small(style(&white.body_small))
            .label_large(style(&white.label_large))
            .label_medium(style(&white.label_medium))
            .label_small(style(&white.label_small));
        assert_eq!(*typography.white, white_copy);
    }

    #[test]
    fn merges_properly_in_the_presence_of_null_fields() {
        test_widgets(|tester| {
            let partial_theme =
                TextTheme::new().title_large(TextStyle::new().color(Color::new(0xcafefeed)));
            let full_theme = ThemeData::fallback(&tester.cell.borrow(), None)
                .text_theme
                .merge(Some(&partial_theme));
            assert_eq!(
                full_theme.title_large.and_then(|style| style.color),
                color(Color::new(0xcafefeed))
            );
        });

        let only_headline_small_and_title_large = TextTheme::new()
            .headline_small(TextStyle::new().color(Color::new(0xcafefeed)))
            .title_large(TextStyle::new().color(Color::new(0xbeefcafe)));
        let only_body_medium_and_title_large = TextTheme::new()
            .body_medium(TextStyle::new().color(Color::new(0xfeedfeed)))
            .title_large(TextStyle::new().color(Color::new(0xdeadcafe)));
        let merged =
            only_headline_small_and_title_large.merge(Some(&only_body_medium_and_title_large));
        assert!(merged.body_large.is_none());
        assert_eq!(
            merged.body_medium.and_then(|style| style.color),
            color(Color::new(0xfeedfeed))
        );
        assert_eq!(
            merged.headline_small.and_then(|style| style.color),
            color(Color::new(0xcafefeed))
        );
        assert_eq!(
            merged.title_large.and_then(|style| style.color),
            color(Color::new(0xdeadcafe))
        );

        let merged = only_headline_small_and_title_large.merge(None);
        assert_eq!(merged, only_headline_small_and_title_large);
    }

    #[test]
    fn apply_applies_custom_properties() {
        // The `displayColor` is applied to [displayLarge], [displayMedium],
        // [displaySmall], [headlineLarge], [headlineMedium], and [bodySmall]. The
        // `bodyColor` is applied to the remaining text styles.
        let display_color = Color::new(0x00000001);
        let body_color = Color::new(0x00000002);
        let font_family = "fontFamily";
        let font_family_fallback: Vec<String> =
            ["font", "family", "fallback"].map(String::from).to_vec();
        let decoration_color = Color::new(0x00000003);
        let decoration_style = waft_embedder::TextDecorationStyle::Dashed;
        let decoration =
            TextDecoration::combine(&[TextDecoration::UNDERLINE, TextDecoration::LINE_THROUGH]);

        let typography = Typography::material2018().build();
        let theme = typography
            .black
            .apply()
            .font_family(font_family)
            .font_family_fallback(font_family_fallback.clone())
            .display_color(display_color)
            .body_color(body_color)
            .decoration(decoration)
            .decoration_color(decoration_color)
            .decoration_style(decoration_style)
            .into_text_theme();

        let display = color(display_color);
        let body = color(body_color);
        let colors = styles(&theme).map(|style| style.color.clone());
        assert_eq!(
            colors,
            [
                display.clone(),
                display.clone(),
                display.clone(),
                display.clone(),
                display.clone(),
                body.clone(),
                body.clone(),
                body.clone(),
                body.clone(),
                body.clone(),
                body.clone(),
                display,
                body.clone(),
                body.clone(),
                body,
            ]
        );

        for style in styles(&theme) {
            assert_eq!(style.font_family.as_deref(), Some(font_family));
            assert_eq!(
                style.font_family_fallback_list(),
                Some(font_family_fallback.clone())
            );
            assert_eq!(style.decoration_color, color(decoration_color));
            assert_eq!(style.decoration_style, Some(decoration_style));
            assert_eq!(style.decoration, Some(decoration));
        }
    }

    #[test]
    fn apply_applies_package_font_family_and_font_family_fallback() {
        let typography = Typography::material2018().build();
        let theme = typography
            .black
            .apply()
            .font_family("fontFamily")
            .font_family_fallback(vec!["fallback".to_string()])
            .package("package")
            .into_text_theme();

        for style in styles(&theme) {
            assert_eq!(
                style.font_family.as_deref(),
                Some("packages/package/fontFamily")
            );
            assert_eq!(
                style.font_family_fallback_list(),
                Some(vec!["packages/package/fallback".to_string()])
            );
        }
    }

    #[test]
    fn apply_leaves_null_styles_null() {
        let body_color = Color::new(0x00000002);
        let theme = TextTheme::new()
            .body_medium(TextStyle::new().font_size(10.0))
            .apply()
            .body_color(body_color)
            .display_color(body_color)
            .font_family("fontFamily")
            .into_text_theme();

        assert_eq!(
            theme,
            TextTheme::new().body_medium(
                TextStyle::new()
                    .font_size(10.0)
                    .color(body_color)
                    .font_family("fontFamily")
            )
        );
    }

    #[test]
    fn apply_applies_font_features_and_font_variations() {
        let font_features = vec![FontFeature::enable("smcp")];
        let font_variations = vec![FontVariation::new("wght", 400.0)];
        let typography = Typography::material2018().build();
        let theme = typography
            .black
            .apply()
            .font_features(font_features.clone())
            .font_variations(font_variations.clone())
            .into_text_theme();

        for style in styles(&theme) {
            assert_eq!(style.font_features, Some(font_features.clone()));
            assert_eq!(style.font_variations, Some(font_variations.clone()));
        }
    }

    #[test]
    fn apply_without_font_features_or_font_variations_preserves_the_originals() {
        let font_features = vec![FontFeature::enable("smcp")];
        let font_variations = vec![FontVariation::new("wght", 400.0)];
        let typography = Typography::material2018().build();
        let display_large = typography
            .black
            .display_large
            .as_ref()
            .expect("a display style")
            .copy_with()
            .font_features(font_features.clone())
            .font_variations(font_variations.clone());
        let base_theme = typography.black.copy_with().display_large(display_large);
        let theme = base_theme.apply().into_text_theme();

        let display_large = theme.display_large.as_ref().expect("a display style");
        assert_eq!(display_large.font_features, Some(font_features));
        assert_eq!(display_large.font_variations, Some(font_variations));
        let display_medium = theme.display_medium.as_ref().expect("a display style");
        assert!(display_medium.font_features.is_none());
        assert!(display_medium.font_variations.is_none());
    }

    #[test]
    fn apply_font_size_factor_and_font_size_delta() {
        let typography = Typography::material2018().build();
        let base_theme = Typography::english_like2018().merge(Some(&typography.black));
        let size_theme = base_theme
            .apply()
            .font_size_factor(2.0)
            .font_size_delta(5.0)
            .into_text_theme();

        for (sized, base) in styles(&size_theme).into_iter().zip(styles(&base_theme)) {
            assert_eq!(
                sized.font_size,
                Some(base.font_size.expect("a size") * 2.0 + 5.0)
            );
        }
    }

    #[test]
    fn apply_letter_spacing_factor_and_letter_spacing_delta() {
        let typography = Typography::material2018().build();
        let base_theme = Typography::english_like2018().merge(Some(&typography.black));
        let size_theme = base_theme
            .apply()
            .letter_spacing_factor(2.0)
            .letter_spacing_delta(5.0)
            .into_text_theme();

        for (sized, base) in styles(&size_theme).into_iter().zip(styles(&base_theme)) {
            assert_eq!(
                sized.letter_spacing,
                Some(base.letter_spacing.expect("a letter spacing") * 2.0 + 5.0)
            );
        }
    }

    #[test]
    fn apply_word_spacing_factor_and_word_spacing_delta() {
        let typography = Typography::material2018().build();
        let base_theme = Typography::english_like2018().merge(Some(&typography.black));
        let with_word_spacing = |style: &Option<TextStyle>| {
            style
                .as_ref()
                .expect("a style")
                .copy_with()
                .word_spacing(1.0)
        };
        let mut base_theme_with_word_spacing = base_theme.copy_with();
        for style in [
            &mut base_theme_with_word_spacing.display_large,
            &mut base_theme_with_word_spacing.display_medium,
            &mut base_theme_with_word_spacing.display_small,
            &mut base_theme_with_word_spacing.headline_large,
            &mut base_theme_with_word_spacing.headline_medium,
            &mut base_theme_with_word_spacing.headline_small,
            &mut base_theme_with_word_spacing.title_large,
            &mut base_theme_with_word_spacing.title_medium,
            &mut base_theme_with_word_spacing.title_small,
            &mut base_theme_with_word_spacing.body_large,
            &mut base_theme_with_word_spacing.body_medium,
            &mut base_theme_with_word_spacing.body_small,
            &mut base_theme_with_word_spacing.label_large,
            &mut base_theme_with_word_spacing.label_medium,
            &mut base_theme_with_word_spacing.label_small,
        ] {
            *style = Some(with_word_spacing(style));
        }
        let size_theme = base_theme_with_word_spacing
            .apply()
            .word_spacing_factor(2.0)
            .word_spacing_delta(5.0)
            .into_text_theme();

        for (sized, base) in styles(&size_theme)
            .into_iter()
            .zip(styles(&base_theme_with_word_spacing))
        {
            assert_eq!(
                sized.word_spacing,
                Some(base.word_spacing.expect("a word spacing") * 2.0 + 5.0)
            );
        }
    }

    #[test]
    fn apply_height_factor_and_height_delta() {
        let typography = Typography::material2021().build();
        let base_theme = Typography::english_like2021().merge(Some(&typography.black));
        let size_theme = base_theme
            .apply()
            .height_factor(2.0)
            .height_delta(5.0)
            .into_text_theme();

        for (sized, base) in styles(&size_theme).into_iter().zip(styles(&base_theme)) {
            assert_eq!(
                sized.height,
                Some(base.height.expect("a height") * 2.0 + 5.0)
            );
        }
    }

    #[test]
    fn lerp_with_one_parameter_null_lerps_each_style_with_null() {
        let theme = Typography::material2018().build().black;
        let lerped = TextTheme::lerp(Some(&theme), None, 0.25);
        for (lerped, style) in optional_styles(&lerped)
            .into_iter()
            .zip(optional_styles(&theme))
        {
            assert_eq!(*lerped, TextStyle::lerp(style.as_ref(), None, 0.25));
        }

        let lerped = TextTheme::lerp(None, Some(&theme), 0.25);
        for (lerped, style) in optional_styles(&lerped)
            .into_iter()
            .zip(optional_styles(&theme))
        {
            assert_eq!(*lerped, TextStyle::lerp(None, style.as_ref(), 0.25));
        }
    }

    #[test]
    fn lerp_with_null_parameters_is_empty() {
        let lerped = TextTheme::lerp(None, None, 0.25);
        for style in optional_styles(&lerped) {
            assert!(style.is_none());
        }
    }

    #[test]
    fn text_theme_of_and_primary_of_are_the_ambient_theme_text_themes() {
        test_widgets(|tester| {
            let (theme, text_theme, primary_text_theme) = probe(
                tester,
                |app, child| {
                    let data = ThemeData::builder()
                        .text_theme(
                            TextTheme::new().display_large(
                                TextStyle::new()
                                    .color(Colors::BLUE.primary())
                                    .font_size(30.0),
                            ),
                        )
                        .primary_text_theme(
                            TextTheme::new().display_large(
                                TextStyle::new()
                                    .background_color(Colors::GREEN.primary())
                                    .font_style(FontStyle::Italic),
                            ),
                        )
                        .build(app);
                    Theme::new(data, child).into_widget()
                },
                |app, context| {
                    (
                        Theme::of(app, context),
                        TextTheme::of(app, context),
                        TextTheme::primary_of(app, context),
                    )
                },
            );
            assert_eq!(text_theme, theme.text_theme);
            assert_eq!(primary_text_theme, theme.primary_text_theme);
            assert_eq!(theme.brightness(), Brightness::Light);
        });
    }
}