Unverified Commit 7f122c74 authored by Mehmet Fidanboylu's avatar Mehmet Fidanboylu Committed by GitHub

Revert "Ensure time picker input mode lays out correctly in RTL (#63599)" (#64094)

This reverts commit 1de673bc.
parent bd6252eb
...@@ -1414,68 +1414,58 @@ class _TimePickerInputState extends State<_TimePickerInput> { ...@@ -1414,68 +1414,58 @@ class _TimePickerInputState extends State<_TimePickerInput> {
), ),
const SizedBox(width: 12.0), const SizedBox(width: 12.0),
], ],
Expanded( Expanded(child: Column(
child: Row( crossAxisAlignment: CrossAxisAlignment.start,
// Hour/minutes should not change positions in RTL locales. children: <Widget>[
textDirection: TextDirection.ltr, const SizedBox(height: 8.0),
children: <Widget>[ _HourMinuteTextField(
Expanded( selectedTime: _selectedTime,
child: Column( isHour: true,
crossAxisAlignment: CrossAxisAlignment.start, style: hourMinuteStyle,
children: <Widget>[ validator: _validateHour,
const SizedBox(height: 8.0), onSavedSubmitted: _handleHourSavedSubmitted,
_HourTextField( onChanged: _handleHourChanged,
selectedTime: _selectedTime, ),
style: hourMinuteStyle, const SizedBox(height: 8.0),
validator: _validateHour, if (!hourHasError && !minuteHasError)
onSavedSubmitted: _handleHourSavedSubmitted, ExcludeSemantics(
onChanged: _handleHourChanged, child: Text(
), MaterialLocalizations.of(context).timePickerHourLabel,
const SizedBox(height: 8.0), style: theme.textTheme.caption,
if (!hourHasError && !minuteHasError) maxLines: 1,
ExcludeSemantics( overflow: TextOverflow.ellipsis,
child: Text(
MaterialLocalizations.of(context).timePickerHourLabel,
style: theme.textTheme.caption,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
), ),
), ),
Container( ],
margin: const EdgeInsets.only(top: 8.0), )),
height: _kTimePickerHeaderControlHeight, Container(
child: _StringFragment(timeOfDayFormat: timeOfDayFormat), margin: const EdgeInsets.only(top: 8.0),
), height: _kTimePickerHeaderControlHeight,
Expanded( child: _StringFragment(timeOfDayFormat: timeOfDayFormat),
child: Column( ),
crossAxisAlignment: CrossAxisAlignment.start, Expanded(child: Column(
children: <Widget>[ crossAxisAlignment: CrossAxisAlignment.start,
const SizedBox(height: 8.0), children: <Widget>[
_MinuteTextField( const SizedBox(height: 8.0),
selectedTime: _selectedTime, _HourMinuteTextField(
style: hourMinuteStyle, selectedTime: _selectedTime,
validator: _validateMinute, isHour: false,
onSavedSubmitted: _handleMinuteSavedSubmitted, style: hourMinuteStyle,
), validator: _validateMinute,
const SizedBox(height: 8.0), onSavedSubmitted: _handleMinuteSavedSubmitted,
if (!hourHasError && !minuteHasError) ),
ExcludeSemantics( const SizedBox(height: 8.0),
child: Text( if (!hourHasError && !minuteHasError)
MaterialLocalizations.of(context).timePickerMinuteLabel, ExcludeSemantics(
style: theme.textTheme.caption, child: Text(
maxLines: 1, MaterialLocalizations.of(context).timePickerMinuteLabel,
overflow: TextOverflow.ellipsis, style: theme.textTheme.caption,
), maxLines: 1,
), overflow: TextOverflow.ellipsis,
],
), ),
), ),
], ],
), )),
),
if (!use24HourDials && timeOfDayFormat != TimeOfDayFormat.a_space_h_colon_mm) ...<Widget>[ if (!use24HourDials && timeOfDayFormat != TimeOfDayFormat.a_space_h_colon_mm) ...<Widget>[
const SizedBox(width: 12.0), const SizedBox(width: 12.0),
_DayPeriodControl( _DayPeriodControl(
...@@ -1499,61 +1489,6 @@ class _TimePickerInputState extends State<_TimePickerInput> { ...@@ -1499,61 +1489,6 @@ class _TimePickerInputState extends State<_TimePickerInput> {
} }
} }
class _HourTextField extends StatelessWidget {
const _HourTextField({
Key key,
@required this.selectedTime,
@required this.style,
@required this.validator,
@required this.onSavedSubmitted,
@required this.onChanged,
}) : super(key: key);
final TimeOfDay selectedTime;
final TextStyle style;
final FormFieldValidator<String> validator;
final ValueChanged<String> onSavedSubmitted;
final ValueChanged<String> onChanged;
@override
Widget build(BuildContext context) {
return _HourMinuteTextField(
selectedTime: selectedTime,
isHour: true,
style: style,
validator: validator,
onSavedSubmitted: onSavedSubmitted,
onChanged: onChanged,
);
}
}
class _MinuteTextField extends StatelessWidget {
const _MinuteTextField({
Key key,
@required this.selectedTime,
@required this.style,
@required this.validator,
@required this.onSavedSubmitted,
}) : super(key: key);
final TimeOfDay selectedTime;
final TextStyle style;
final FormFieldValidator<String> validator;
final ValueChanged<String> onSavedSubmitted;
@override
Widget build(BuildContext context) {
return _HourMinuteTextField(
selectedTime: selectedTime,
isHour: false,
style: style,
validator: validator,
onSavedSubmitted: onSavedSubmitted,
);
}
}
class _HourMinuteTextField extends StatefulWidget { class _HourMinuteTextField extends StatefulWidget {
const _HourMinuteTextField({ const _HourMinuteTextField({
Key key, Key key,
......
...@@ -8,16 +8,10 @@ import 'package:flutter_localizations/flutter_localizations.dart'; ...@@ -8,16 +8,10 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
class _TimePickerLauncher extends StatelessWidget { class _TimePickerLauncher extends StatelessWidget {
const _TimePickerLauncher({ const _TimePickerLauncher({ Key key, this.onChanged, this.locale }) : super(key: key);
Key key,
this.onChanged,
this.locale,
this.entryMode = TimePickerEntryMode.dial,
}) : super(key: key);
final ValueChanged<TimeOfDay> onChanged; final ValueChanged<TimeOfDay> onChanged;
final Locale locale; final Locale locale;
final TimePickerEntryMode entryMode;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -34,7 +28,6 @@ class _TimePickerLauncher extends StatelessWidget { ...@@ -34,7 +28,6 @@ class _TimePickerLauncher extends StatelessWidget {
onPressed: () async { onPressed: () async {
onChanged(await showTimePicker( onChanged(await showTimePicker(
context: context, context: context,
initialEntryMode: entryMode,
initialTime: const TimeOfDay(hour: 7, minute: 0), initialTime: const TimeOfDay(hour: 7, minute: 0),
)); ));
}, },
...@@ -214,73 +207,6 @@ void main() { ...@@ -214,73 +207,6 @@ void main() {
tester.binding.window.devicePixelRatioTestValue = null; tester.binding.window.devicePixelRatioTestValue = null;
}); });
testWidgets('can localize input mode in all known formats', (WidgetTester tester) async {
final Finder stringFragmentTextFinder = find.descendant(
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_StringFragment'),
matching: find.byType(Text),
).first;
final Finder hourControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_HourTextField');
final Finder minuteControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_MinuteTextField');
final Finder dayPeriodControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodControl');
// TODO(yjbanov): also test `HH.mm` (in_ID), `a h:mm` (ko_KR) and `HH:mm น.` (th_TH) when we have .arb files for them
final List<Locale> locales = <Locale>[
const Locale('en', 'US'), //'h:mm a'
const Locale('en', 'GB'), //'HH:mm'
const Locale('es', 'ES'), //'H:mm'
const Locale('fr', 'CA'), //'HH \'h\' mm'
const Locale('zh', 'ZH'), //'ah:mm'
const Locale('fa', 'IR'), //'H:mm' but RTL
];
for (final Locale locale in locales) {
await tester.pumpWidget(_TimePickerLauncher(onChanged: (TimeOfDay time) { }, locale: locale, entryMode: TimePickerEntryMode.input));
await tester.tap(find.text('X'));
await tester.pumpAndSettle(const Duration(seconds: 1));
final Text stringFragmentText = tester.widget(stringFragmentTextFinder);
final double hourLeftOffset = tester.getTopLeft(hourControlFinder).dx;
final double minuteLeftOffset = tester.getTopLeft(minuteControlFinder).dx;
final double stringFragmentLeftOffset = tester.getTopLeft(stringFragmentTextFinder).dx;
if (locale == const Locale('en', 'US')) {
final double dayPeriodLeftOffset = tester.getTopLeft(dayPeriodControlFinder).dx;
expect(stringFragmentText.data, ':');
expect(hourLeftOffset, lessThan(stringFragmentLeftOffset));
expect(stringFragmentLeftOffset, lessThan(minuteLeftOffset));
expect(minuteLeftOffset, lessThan(dayPeriodLeftOffset));
} else if (locale == const Locale('en', 'GB')) {
expect(stringFragmentText.data, ':');
expect(hourLeftOffset, lessThan(stringFragmentLeftOffset));
expect(stringFragmentLeftOffset, lessThan(minuteLeftOffset));
expect(dayPeriodControlFinder, findsNothing);
} else if (locale == const Locale('es', 'ES')) {
expect(stringFragmentText.data, ':');
expect(hourLeftOffset, lessThan(stringFragmentLeftOffset));
expect(stringFragmentLeftOffset, lessThan(minuteLeftOffset));
expect(dayPeriodControlFinder, findsNothing);
} else if (locale == const Locale('fr', 'CA')) {
expect(stringFragmentText.data, 'h');
expect(hourLeftOffset, lessThan(stringFragmentLeftOffset));
expect(stringFragmentLeftOffset, lessThan(minuteLeftOffset));
expect(dayPeriodControlFinder, findsNothing);
} else if (locale == const Locale('zh', 'ZH')) {
final double dayPeriodLeftOffset = tester.getTopLeft(dayPeriodControlFinder).dx;
expect(stringFragmentText.data, ':');
expect(dayPeriodLeftOffset, lessThan(hourLeftOffset));
expect(hourLeftOffset, lessThan(stringFragmentLeftOffset));
expect(stringFragmentLeftOffset, lessThan(minuteLeftOffset));
} else if (locale == const Locale('fa', 'IR')) {
// Even though this is an RTL locale, the hours and minutes positions should remain the same.
expect(stringFragmentText.data, ':');
expect(hourLeftOffset, lessThan(stringFragmentLeftOffset));
expect(stringFragmentLeftOffset, lessThan(minuteLeftOffset));
expect(dayPeriodControlFinder, findsNothing);
}
await finishPicker(tester);
}
});
testWidgets('uses single-ring 24-hour dial for all formats', (WidgetTester tester) async { testWidgets('uses single-ring 24-hour dial for all formats', (WidgetTester tester) async {
const List<Locale> locales = <Locale>[ const List<Locale> locales = <Locale>[
Locale('en', 'US'), // h Locale('en', 'US'), // h
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment