Honor the InputDecoratorTheme in the text input fields used by the Date Pickers. (#57189)
This commit is contained in:
@@ -9,6 +9,7 @@ import '../input_border.dart';
|
||||
import '../input_decorator.dart';
|
||||
import '../material_localizations.dart';
|
||||
import '../text_form_field.dart';
|
||||
import '../theme.dart';
|
||||
|
||||
import 'date_picker_common.dart';
|
||||
import 'date_utils.dart' as utils;
|
||||
@@ -219,27 +220,24 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
return OrientationBuilder(builder: (BuildContext context, Orientation orientation) {
|
||||
assert(orientation != null);
|
||||
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
border: const UnderlineInputBorder(),
|
||||
filled: true,
|
||||
hintText: widget.fieldHintText ?? localizations.dateHelpText,
|
||||
labelText: widget.fieldLabelText ?? localizations.dateInputLabel,
|
||||
),
|
||||
validator: _validateDate,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
DateTextInputFormatter(localizations.dateSeparator),
|
||||
],
|
||||
keyboardType: TextInputType.datetime,
|
||||
onSaved: _handleSaved,
|
||||
onFieldSubmitted: _handleSubmitted,
|
||||
autofocus: widget.autofocus,
|
||||
controller: _controller,
|
||||
);
|
||||
});
|
||||
final InputDecorationTheme inputTheme = Theme.of(context).inputDecorationTheme;
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
border: inputTheme.border ?? const UnderlineInputBorder(),
|
||||
filled: inputTheme.filled ?? true,
|
||||
hintText: widget.fieldHintText ?? localizations.dateHelpText,
|
||||
labelText: widget.fieldLabelText ?? localizations.dateInputLabel,
|
||||
),
|
||||
validator: _validateDate,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
DateTextInputFormatter(localizations.dateSeparator),
|
||||
],
|
||||
keyboardType: TextInputType.datetime,
|
||||
onSaved: _handleSaved,
|
||||
onFieldSubmitted: _handleSubmitted,
|
||||
autofocus: widget.autofocus,
|
||||
controller: _controller,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../input_border.dart';
|
||||
import '../input_decorator.dart';
|
||||
import '../material_localizations.dart';
|
||||
import '../text_field.dart';
|
||||
import '../theme.dart';
|
||||
|
||||
import 'date_utils.dart' as utils;
|
||||
import 'input_date_picker.dart' show DateTextInputFormatter;
|
||||
@@ -230,6 +231,7 @@ class InputDateRangePickerState extends State<InputDateRangePicker> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
final InputDecorationTheme inputTheme = Theme.of(context).inputDecorationTheme;
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
@@ -237,8 +239,8 @@ class InputDateRangePickerState extends State<InputDateRangePicker> {
|
||||
child: TextField(
|
||||
controller: _startController,
|
||||
decoration: InputDecoration(
|
||||
border: const UnderlineInputBorder(),
|
||||
filled: true,
|
||||
border: inputTheme.border ?? const UnderlineInputBorder(),
|
||||
filled: inputTheme.filled ?? true,
|
||||
hintText: widget.fieldStartHintText ?? localizations.dateHelpText,
|
||||
labelText: widget.fieldStartLabelText ?? localizations.dateRangeStartLabel,
|
||||
errorText: _startErrorText,
|
||||
@@ -254,8 +256,8 @@ class InputDateRangePickerState extends State<InputDateRangePicker> {
|
||||
child: TextField(
|
||||
controller: _endController,
|
||||
decoration: InputDecoration(
|
||||
border: const UnderlineInputBorder(),
|
||||
filled: true,
|
||||
border: inputTheme.border ?? const UnderlineInputBorder(),
|
||||
filled: inputTheme.filled ?? true,
|
||||
hintText: widget.fieldEndHintText ?? localizations.dateHelpText,
|
||||
labelText: widget.fieldEndLabelText ?? localizations.dateRangeEndLabel,
|
||||
errorText: _endErrorText,
|
||||
|
||||
@@ -679,6 +679,63 @@ void main() {
|
||||
expect(find.text(errorInvalidText), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('InputDecorationTheme is honored', (WidgetTester tester) async {
|
||||
BuildContext buttonContext;
|
||||
const InputBorder border = InputBorder.none;
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
theme: ThemeData.light().copyWith(
|
||||
inputDecorationTheme: const InputDecorationTheme(
|
||||
filled: false,
|
||||
border: border,
|
||||
),
|
||||
),
|
||||
home: Material(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return RaisedButton(
|
||||
onPressed: () {
|
||||
buttonContext = context;
|
||||
},
|
||||
child: const Text('Go'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
await tester.tap(find.text('Go'));
|
||||
expect(buttonContext, isNotNull);
|
||||
|
||||
showDatePicker(
|
||||
context: buttonContext,
|
||||
initialDate: initialDate,
|
||||
firstDate: firstDate,
|
||||
lastDate: lastDate,
|
||||
currentDate: today,
|
||||
initialEntryMode: DatePickerEntryMode.input,
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Get the border and container color from the painter of the _BorderContainer
|
||||
// (this was cribbed from input_decorator_test.dart).
|
||||
final CustomPaint customPaint = tester.widget(find.descendant(
|
||||
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_BorderContainer'),
|
||||
matching: find.byWidgetPredicate((Widget w) => w is CustomPaint),
|
||||
));
|
||||
final dynamic/*_InputBorderPainter*/ inputBorderPainter = customPaint.foregroundPainter;
|
||||
final dynamic/*_InputBorderTween*/ inputBorderTween = inputBorderPainter.border;
|
||||
final Animation<double> animation = inputBorderPainter.borderAnimation as Animation<double>;
|
||||
final InputBorder actualBorder = inputBorderTween.evaluate(animation) as InputBorder;
|
||||
final Color containerColor = inputBorderPainter.blendedColor as Color;
|
||||
|
||||
// Border should match
|
||||
expect(actualBorder, equals(border));
|
||||
|
||||
// It shouldn't be filled, so the color should be transparent
|
||||
expect(containerColor, equals(Colors.transparent));
|
||||
});
|
||||
});
|
||||
|
||||
group('Haptic feedback', () {
|
||||
|
||||
@@ -408,5 +408,67 @@ void main() {
|
||||
expect(find.text('End Date'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('InputDecorationTheme is honored', (WidgetTester tester) async {
|
||||
|
||||
// Given a custom paint for an input decoration, extract the border and
|
||||
// fill color and test them against the expected values.
|
||||
void _testInputDecorator(CustomPaint decoratorPaint, InputBorder expectedBorder, Color expectedContainerColor) {
|
||||
final dynamic/*_InputBorderPainter*/ inputBorderPainter = decoratorPaint.foregroundPainter;
|
||||
final dynamic/*_InputBorderTween*/ inputBorderTween = inputBorderPainter.border;
|
||||
final Animation<double> animation = inputBorderPainter.borderAnimation as Animation<double>;
|
||||
final InputBorder actualBorder = inputBorderTween.evaluate(animation) as InputBorder;
|
||||
final Color containerColor = inputBorderPainter.blendedColor as Color;
|
||||
|
||||
expect(actualBorder, equals(expectedBorder));
|
||||
expect(containerColor, equals(expectedContainerColor));
|
||||
}
|
||||
|
||||
BuildContext buttonContext;
|
||||
const InputBorder border = InputBorder.none;
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
theme: ThemeData.light().copyWith(
|
||||
inputDecorationTheme: const InputDecorationTheme(
|
||||
filled: false,
|
||||
border: border,
|
||||
),
|
||||
),
|
||||
home: Material(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return RaisedButton(
|
||||
onPressed: () {
|
||||
buttonContext = context;
|
||||
},
|
||||
child: const Text('Go'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
await tester.tap(find.text('Go'));
|
||||
expect(buttonContext, isNotNull);
|
||||
|
||||
showDateRangePicker(
|
||||
context: buttonContext,
|
||||
initialDateRange: initialDateRange,
|
||||
firstDate: firstDate,
|
||||
lastDate: lastDate,
|
||||
initialEntryMode: DatePickerEntryMode.input,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final Finder borderContainers = find.descendant(
|
||||
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_BorderContainer'),
|
||||
matching: find.byWidgetPredicate((Widget w) => w is CustomPaint),
|
||||
);
|
||||
|
||||
// Test the start date text field
|
||||
_testInputDecorator(tester.widget(borderContainers.first), border, Colors.transparent);
|
||||
|
||||
// Test the end date text field
|
||||
_testInputDecorator(tester.widget(borderContainers.last), border, Colors.transparent);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user