Fix error when choose noon on time picker (#78478)
This commit is contained in:
parent
26b9a01531
commit
6dd77cc4f8
@ -91,7 +91,7 @@ class TimeOfDay {
|
||||
DayPeriod get period => hour < hoursPerPeriod ? DayPeriod.am : DayPeriod.pm;
|
||||
|
||||
/// Which hour of the current period (e.g., am or pm) this time is.
|
||||
int get hourOfPeriod => hour - periodOffset;
|
||||
int get hourOfPeriod => hour > hoursPerPeriod ? hour - periodOffset : hour;
|
||||
|
||||
/// The hour at which the current period starts.
|
||||
int get periodOffset => period == DayPeriod.am ? 0 : hoursPerPeriod;
|
||||
|
@ -25,5 +25,24 @@ void main() {
|
||||
expect(await pumpTest(false), '7:00 AM');
|
||||
expect(await pumpTest(true), '07:00');
|
||||
});
|
||||
|
||||
testWidgets('return 12 hours at noon', (WidgetTester tester) async {
|
||||
Future<String> pumpTest(bool alwaysUse24HourFormat) async {
|
||||
late String formattedValue;
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(alwaysUse24HourFormat: alwaysUse24HourFormat),
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
formattedValue = const TimeOfDay(hour: 12, minute: 0).format(context);
|
||||
return Container();
|
||||
}),
|
||||
),
|
||||
));
|
||||
return formattedValue;
|
||||
}
|
||||
|
||||
expect(await pumpTest(false), '12:00 PM');
|
||||
expect(await pumpTest(true), '12:00');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user