1
- import 'dart:math' as math;
2
-
1
+ import 'package:flutter/foundation.dart' ;
3
2
import 'package:flutter/material.dart' hide YearPicker;
4
3
5
4
import 'l10n/month_year_picker_localizations.dart' ;
@@ -31,7 +30,7 @@ Future<DateTime?> showMonthYearPicker({
31
30
TextDirection ? textDirection,
32
31
TransitionBuilder ? builder,
33
32
MonthYearPickerMode initialMonthYearPickerMode = MonthYearPickerMode .month,
34
- }) async {
33
+ }) {
35
34
initialDate = monthYearOnly (initialDate);
36
35
firstDate = monthYearOnly (firstDate);
37
36
lastDate = monthYearOnly (lastDate);
@@ -48,9 +47,18 @@ Future<DateTime?> showMonthYearPicker({
48
47
! initialDate.isAfter (lastDate),
49
48
'initialDate $initialDate must be on or before lastDate $lastDate .' ,
50
49
);
51
- assert (debugCheckHasMaterialLocalizations (context));
52
- assert (debugCheckHasMonthYearPickerLocalizations (context));
53
- assert (debugCheckHasDirectionality (context));
50
+ assert (
51
+ debugCheckHasMaterialLocalizations (context),
52
+ 'No MaterialLocalizations found.' ,
53
+ );
54
+ assert (
55
+ debugCheckHasMonthYearPickerLocalizations (context),
56
+ 'No MonthYearPickerLocalizations found.' ,
57
+ );
58
+ assert (
59
+ debugCheckHasDirectionality (context),
60
+ 'No Directionality found.' ,
61
+ );
54
62
55
63
Widget dialog = MonthYearPickerDialog (
56
64
initialDate: initialDate,
@@ -75,7 +83,7 @@ Future<DateTime?> showMonthYearPicker({
75
83
);
76
84
}
77
85
78
- return await showDialog <DateTime >(
86
+ return showDialog <DateTime >(
79
87
context: context,
80
88
useRootNavigator: useRootNavigator,
81
89
routeSettings: routeSettings,
@@ -93,13 +101,13 @@ enum MonthYearPickerMode {
93
101
class MonthYearPickerDialog extends StatefulWidget {
94
102
// ------------------------------- CONSTRUCTORS ------------------------------
95
103
const MonthYearPickerDialog ({
96
- Key ? key,
104
+ super . key,
97
105
required this .initialDate,
98
106
required this .firstDate,
99
107
required this .lastDate,
100
108
required this .initialMonthYearPickerMode,
101
109
this .selectableMonthYearPredicate,
102
- }) : super (key : key) ;
110
+ });
103
111
104
112
// ---------------------------------- FIELDS ---------------------------------
105
113
final DateTime initialDate;
@@ -111,6 +119,27 @@ class MonthYearPickerDialog extends StatefulWidget {
111
119
// --------------------------------- METHODS ---------------------------------
112
120
@override
113
121
State <MonthYearPickerDialog > createState () => _MonthYearPickerDialogState ();
122
+
123
+ @override
124
+ void debugFillProperties (DiagnosticPropertiesBuilder properties) {
125
+ super .debugFillProperties (properties);
126
+ properties
127
+ ..add (DiagnosticsProperty <DateTime >('initialDate' , initialDate))
128
+ ..add (DiagnosticsProperty <DateTime >('firstDate' , firstDate))
129
+ ..add (DiagnosticsProperty <DateTime >('lastDate' , lastDate))
130
+ ..add (
131
+ EnumProperty <MonthYearPickerMode >(
132
+ 'initialMonthYearPickerMode' ,
133
+ initialMonthYearPickerMode,
134
+ ),
135
+ )
136
+ ..add (
137
+ ObjectFlagProperty <SelectableMonthYearPredicate ?>.has (
138
+ 'selectableMonthYearPredicate' ,
139
+ selectableMonthYearPredicate,
140
+ ),
141
+ );
142
+ }
114
143
}
115
144
116
145
class _MonthYearPickerDialogState extends State <MonthYearPickerDialog > {
@@ -159,7 +188,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
159
188
final textTheme = theme.textTheme;
160
189
// Constrain the textScaleFactor to the largest supported value to prevent
161
190
// layout issues.
162
- final textScaleFactor = math. min ( media.textScaleFactor, 1.3 ) ;
191
+ final textScaler = media.textScaler ;
163
192
final direction = Directionality .of (context);
164
193
165
194
final dateText = materialLocalizations.formatMonthYear (_selectedDate);
@@ -248,7 +277,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
248
277
: Icons .keyboard_arrow_right,
249
278
),
250
279
onPressed: _canGoNext ? _goToNextPage : null ,
251
- )
280
+ ),
252
281
],
253
282
),
254
283
),
@@ -270,7 +299,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
270
299
duration: _dialogSizeAnimationDuration,
271
300
curve: Curves .easeOut,
272
301
left: 0.0 ,
273
- right: ( pickerMaxWidth - (width ?? pickerMaxWidth) ),
302
+ right: pickerMaxWidth - (width ?? pickerMaxWidth),
274
303
top: _isShowingYear ? 0.0 : - constraints.maxHeight,
275
304
bottom: _isShowingYear ? 0.0 : constraints.maxHeight,
276
305
child: SizedBox (
@@ -292,7 +321,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
292
321
duration: _dialogSizeAnimationDuration,
293
322
curve: Curves .easeOut,
294
323
left: 0.0 ,
295
- right: ( pickerMaxWidth - (width ?? pickerMaxWidth) ),
324
+ right: pickerMaxWidth - (width ?? pickerMaxWidth),
296
325
top: _isShowingYear ? constraints.maxHeight : 0.0 ,
297
326
bottom: _isShowingYear ? - constraints.maxHeight : 0.0 ,
298
327
child: SizedBox (
@@ -309,13 +338,12 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
309
338
widget.selectableMonthYearPredicate,
310
339
),
311
340
),
312
- )
341
+ ),
313
342
],
314
343
);
315
344
},
316
345
);
317
346
318
- final dialogSize = _dialogSize * textScaleFactor;
319
347
return Directionality (
320
348
textDirection: direction,
321
349
child: Dialog (
@@ -325,14 +353,12 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
325
353
),
326
354
clipBehavior: Clip .antiAlias,
327
355
child: AnimatedContainer (
328
- width: dialogSize. width,
329
- height: dialogSize. height,
356
+ width: textScaler. scale (_dialogSize. width) ,
357
+ height: textScaler. scale (_dialogSize. height) ,
330
358
duration: _dialogSizeAnimationDuration,
331
359
curve: Curves .easeIn,
332
360
child: MediaQuery (
333
- data: MediaQuery .of (context).copyWith (
334
- textScaleFactor: textScaleFactor,
335
- ),
361
+ data: MediaQuery .of (context).copyWith (textScaler: textScaler),
336
362
child: Builder (
337
363
builder: (context) {
338
364
switch (orientation) {
@@ -406,33 +432,24 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
406
432
}
407
433
}
408
434
409
- void _goToPreviousPage () {
410
- if (_isShowingYear) {
411
- _yearPickerState.currentState! .goDown ();
412
- } else {
413
- _monthPickerState.currentState! .goDown ();
414
- }
415
- }
435
+ Future <void > _goToPreviousPage () => _isShowingYear
436
+ ? _yearPickerState.currentState! .goDown ()
437
+ : _monthPickerState.currentState! .goDown ();
416
438
417
- void _goToNextPage () {
418
- if (_isShowingYear) {
419
- _yearPickerState.currentState! .goUp ();
420
- } else {
421
- _monthPickerState.currentState! .goUp ();
422
- }
423
- }
439
+ Future <void > _goToNextPage () => _isShowingYear
440
+ ? _yearPickerState.currentState! .goUp ()
441
+ : _monthPickerState.currentState! .goUp ();
424
442
}
425
443
426
444
class _Header extends StatelessWidget {
427
445
// ------------------------------- CONSTRUCTORS ------------------------------
428
446
const _Header ({
429
- Key ? key,
430
447
required this .helpText,
431
448
required this .titleText,
432
449
this .titleSemanticsLabel,
433
450
required this .titleStyle,
434
451
required this .orientation,
435
- }) : super (key : key) ;
452
+ });
436
453
437
454
// ---------------------------------- FIELDS ---------------------------------
438
455
final String helpText;
@@ -528,4 +545,15 @@ class _Header extends StatelessWidget {
528
545
);
529
546
}
530
547
}
548
+
549
+ @override
550
+ void debugFillProperties (DiagnosticPropertiesBuilder properties) {
551
+ super .debugFillProperties (properties);
552
+ properties
553
+ ..add (StringProperty ('helpText' , helpText))
554
+ ..add (StringProperty ('titleText' , titleText))
555
+ ..add (StringProperty ('titleSemanticsLabel' , titleSemanticsLabel))
556
+ ..add (DiagnosticsProperty <TextStyle ?>('titleStyle' , titleStyle))
557
+ ..add (EnumProperty <Orientation >('orientation' , orientation));
558
+ }
531
559
}
0 commit comments