@@ -32,6 +32,7 @@ void main() {
32
32
yearForegroundColor: MaterialStatePropertyAll <Color >(Color (0xfffffffa )),
33
33
yearBackgroundColor: MaterialStatePropertyAll <Color >(Color (0xfffffffb )),
34
34
yearOverlayColor: MaterialStatePropertyAll <Color >(Color (0xfffffffc )),
35
+ yearShape: MaterialStatePropertyAll <OutlinedBorder >(RoundedRectangleBorder ()),
35
36
rangePickerBackgroundColor: Color (0xfffffffd ),
36
37
rangePickerElevation: 7 ,
37
38
rangePickerShadowColor: Color (0xfffffffe ),
@@ -69,11 +70,11 @@ void main() {
69
70
);
70
71
}
71
72
72
- BoxDecoration ? findTextDecoration (WidgetTester tester, String date) {
73
+ ShapeDecoration ? findTextDecoration (WidgetTester tester, String date) {
73
74
final Container container = tester.widget <Container >(
74
75
find.ancestor (of: find.text (date), matching: find.byType (Container )).first,
75
76
);
76
- return container.decoration as BoxDecoration ? ;
77
+ return container.decoration as ShapeDecoration ? ;
77
78
}
78
79
79
80
ShapeDecoration ? findDayDecoration (WidgetTester tester, String day) {
@@ -449,6 +450,7 @@ void main() {
449
450
equalsIgnoringHashCodes (TextButton .styleFrom ().toString ()),
450
451
);
451
452
expect (m2.locale, null );
453
+ expect (m2.yearShape? .resolve (< MaterialState > {}), const StadiumBorder ());
452
454
});
453
455
454
456
testWidgets ('Default DatePickerThemeData debugFillProperties' , (WidgetTester tester) async {
@@ -500,6 +502,7 @@ void main() {
500
502
'yearForegroundColor: WidgetStatePropertyAll(${const Color (0xfffffffa )})' ,
501
503
'yearBackgroundColor: WidgetStatePropertyAll(${const Color (0xfffffffb )})' ,
502
504
'yearOverlayColor: WidgetStatePropertyAll(${const Color (0xfffffffc )})' ,
505
+ 'yearShape: WidgetStatePropertyAll(RoundedRectangleBorder(BorderSide(width: 0.0, style: none), BorderRadius.zero))' ,
503
506
'rangePickerBackgroundColor: ${const Color (0xfffffffd )}' ,
504
507
'rangePickerElevation: 7.0' ,
505
508
'rangePickerShadowColor: ${const Color (0xfffffffe )}' ,
@@ -607,30 +610,28 @@ void main() {
607
610
await tester.pumpAndSettle ();
608
611
609
612
final Text year2022 = tester.widget <Text >(find.text ('2022' ));
610
- final BoxDecoration year2022Decoration = findTextDecoration (tester, '2022' )! ;
613
+ final ShapeDecoration year2022Decoration = findTextDecoration (tester, '2022' )! ;
611
614
expect (year2022.style? .fontSize, datePickerTheme.yearStyle? .fontSize);
612
615
expect (year2022.style? .color, datePickerTheme.yearForegroundColor? .resolve (< MaterialState > {}));
613
616
expect (
614
617
year2022Decoration.color,
615
618
datePickerTheme.yearBackgroundColor? .resolve (< MaterialState > {}),
616
619
);
620
+ expect (year2022Decoration.shape, datePickerTheme.yearShape? .resolve (< MaterialState > {}));
617
621
618
622
final Text year2023 = tester.widget <Text >(find.text ('2023' )); // DatePickerDialog.currentDate
619
- final BoxDecoration year2023Decoration = findTextDecoration (tester, '2023' )! ;
623
+ final ShapeDecoration year2023Decoration = findTextDecoration (tester, '2023' )! ;
620
624
expect (year2023.style? .fontSize, datePickerTheme.yearStyle? .fontSize);
621
625
expect (year2023.style? .color, datePickerTheme.todayForegroundColor? .resolve (< MaterialState > {}));
622
626
expect (
623
627
year2023Decoration.color,
624
628
datePickerTheme.todayBackgroundColor? .resolve (< MaterialState > {}),
625
629
);
626
- expect (year2023Decoration.border? .top.width, datePickerTheme.todayBorder? .width);
627
- expect (year2023Decoration.border? .bottom.width, datePickerTheme.todayBorder? .width);
630
+ final RoundedRectangleBorder roundedRectangleBorder =
631
+ year2023Decoration.shape as RoundedRectangleBorder ;
632
+ expect (roundedRectangleBorder.side.width, datePickerTheme.todayBorder? .width);
628
633
expect (
629
- year2023Decoration.border? .top.color,
630
- datePickerTheme.todayForegroundColor? .resolve (< MaterialState > {}),
631
- );
632
- expect (
633
- year2023Decoration.border? .bottom.color,
634
+ roundedRectangleBorder.side.color,
634
635
datePickerTheme.todayForegroundColor? .resolve (< MaterialState > {}),
635
636
);
636
637
@@ -1206,4 +1207,109 @@ void main() {
1206
1207
);
1207
1208
}
1208
1209
});
1210
+
1211
+ testWidgets ('YearPicker maintains default year shape at textScaleFactor 1, 1.5, 2' , (
1212
+ WidgetTester tester,
1213
+ ) async {
1214
+ double textScaleFactor = 1.0 ;
1215
+ Widget buildFrame () {
1216
+ return MaterialApp (
1217
+ home: Builder (
1218
+ builder: (BuildContext context) {
1219
+ return MediaQuery .withClampedTextScaling (
1220
+ minScaleFactor: textScaleFactor,
1221
+ maxScaleFactor: textScaleFactor,
1222
+ child: Scaffold (
1223
+ body: YearPicker (
1224
+ currentDate: DateTime (2025 ),
1225
+ firstDate: DateTime (2021 ),
1226
+ lastDate: DateTime (2030 ),
1227
+ selectedDate: DateTime (2025 ),
1228
+ onChanged: (DateTime value) {},
1229
+ ),
1230
+ ),
1231
+ );
1232
+ },
1233
+ ),
1234
+ );
1235
+ }
1236
+
1237
+ await tester.pumpWidget (buildFrame ());
1238
+
1239
+ // Find container whose child is text 2025.
1240
+ final Finder yearContainer =
1241
+ find.ancestor (of: find.text ('2025' ), matching: find.byType (Container )).first;
1242
+
1243
+ expect (
1244
+ tester.renderObject (yearContainer),
1245
+ paints..rrect (
1246
+ rrect: RRect .fromLTRBR (0.5 , 0.5 , 71.5 , 35.5 , const Radius .circular (17.5 )),
1247
+ color: const Color (0xFF6750A4 ),
1248
+ ),
1249
+ );
1250
+
1251
+ textScaleFactor = 1.5 ;
1252
+ await tester.pumpWidget (buildFrame ());
1253
+
1254
+ expect (
1255
+ tester.renderObject (yearContainer),
1256
+ paints..rrect (
1257
+ rrect: RRect .fromLTRBR (0.5 , 0.5 , 107.5 , 51.5 , const Radius .circular (25.5 )),
1258
+ color: const Color (0xFF6750A4 ),
1259
+ ),
1260
+ );
1261
+
1262
+ textScaleFactor = 2 ;
1263
+ await tester.pumpWidget (buildFrame ());
1264
+
1265
+ expect (
1266
+ tester.renderObject (yearContainer),
1267
+ paints..rrect (
1268
+ rrect: RRect .fromLTRBR (0.5 , 0.5 , 143.5 , 51.5 , const Radius .circular (25.5 )),
1269
+ color: const Color (0xFF6750A4 ),
1270
+ ),
1271
+ );
1272
+ });
1273
+
1274
+ testWidgets ('YearPicker applies shape from DatePickerThemeData.yearShape correctly' , (
1275
+ WidgetTester tester,
1276
+ ) async {
1277
+ const OutlinedBorder yearShpae = CircleBorder ();
1278
+ await tester.pumpWidget (
1279
+ MaterialApp (
1280
+ theme: ThemeData (
1281
+ datePickerTheme: datePickerTheme.copyWith (
1282
+ yearShape: MaterialStateProperty .all <OutlinedBorder >(yearShpae),
1283
+ ),
1284
+ ),
1285
+ home: Directionality (
1286
+ textDirection: TextDirection .ltr,
1287
+ child: Material (
1288
+ child: Center (
1289
+ child: YearPicker (
1290
+ currentDate: DateTime (2025 ),
1291
+ firstDate: DateTime (2021 ),
1292
+ lastDate: DateTime (2030 ),
1293
+ selectedDate: DateTime (2025 ),
1294
+ onChanged: (DateTime value) {},
1295
+ ),
1296
+ ),
1297
+ ),
1298
+ ),
1299
+ ),
1300
+ );
1301
+
1302
+ final ShapeDecoration year2022Decoration = findTextDecoration (tester, '2022' )! ;
1303
+ final OutlinedBorder year2022roundedRectangleBorder = year2022Decoration.shape as CircleBorder ;
1304
+ expect (year2022roundedRectangleBorder.side.width, 0.0 );
1305
+ expect (year2022roundedRectangleBorder.side.color, yearShpae.side.color);
1306
+
1307
+ final ShapeDecoration year2025Decoration = findTextDecoration (tester, '2025' )! ;
1308
+ final OutlinedBorder year2022RoundedRectangleBorder = year2025Decoration.shape as CircleBorder ;
1309
+ expect (year2022RoundedRectangleBorder.side.width, datePickerTheme.todayBorder? .width);
1310
+ expect (
1311
+ year2022RoundedRectangleBorder.side.color,
1312
+ datePickerTheme.todayForegroundColor? .resolve (< MaterialState > {}),
1313
+ );
1314
+ });
1209
1315
}
0 commit comments