From 8838a8fbfa5ce812f7463e5c08c8965082a6b3a5 Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 8 Feb 2017 17:50:53 -0800 Subject: [PATCH] Allow for customization of hintText style in InputField (#7942) * Allow for customization of hintText in InputField * Adding tests. --- packages/flutter/lib/src/material/input.dart | 10 +++- packages/flutter/test/widgets/input_test.dart | 57 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/input.dart b/packages/flutter/lib/src/material/input.dart index 5b838145a9..5829030880 100644 --- a/packages/flutter/lib/src/material/input.dart +++ b/packages/flutter/lib/src/material/input.dart @@ -47,6 +47,7 @@ class InputField extends StatefulWidget { this.keyboardType: TextInputType.text, this.hintText, this.style, + this.hintStyle, this.obscureText: false, this.maxLines: 1, this.autofocus: false, @@ -69,6 +70,12 @@ class InputField extends StatefulWidget { /// The style to use for the text being edited. final TextStyle style; + /// The style to use for the hint text. + /// + /// Defaults to the specified TextStyle in style with the hintColor from + /// the ThemeData + final TextStyle hintStyle; + /// Whether to hide the text being edited (e.g., for passwords). /// /// When this is set to true, all the characters in the input are replaced by @@ -151,7 +158,8 @@ class _InputFieldState extends State { ]; if (config.hintText != null && value.text.isEmpty) { - TextStyle hintStyle = textStyle.copyWith(color: themeData.hintColor); + TextStyle hintStyle = config.hintStyle ?? + textStyle.copyWith(color: themeData.hintColor); stackChildren.add( new Positioned( left: 0.0, diff --git a/packages/flutter/test/widgets/input_test.dart b/packages/flutter/test/widgets/input_test.dart index c142abe695..497d1954d2 100644 --- a/packages/flutter/test/widgets/input_test.dart +++ b/packages/flutter/test/widgets/input_test.dart @@ -740,6 +740,63 @@ void main() { checkText('Hello World'); }); + testWidgets('InputField with default hintStyle', (WidgetTester tester) async { + InputValue inputValue = InputValue.empty; + TextStyle textStyle = new TextStyle( + color: Colors.pink[500], + fontSize: 10.0, + ); + ThemeData themeData = new ThemeData( + hintColor: Colors.blue[500], + ); + + Widget builder() { + return new Center( + child: new Theme( + data: themeData, + child: new Material( + child: new InputField( + value: inputValue, + hintText: 'Placeholder', + style: textStyle, + ), + ), + ), + ); + } + + await tester.pumpWidget(builder()); + + Text hintText = tester.widget(find.text('Placeholder')); + expect(hintText.style.color, themeData.hintColor); + expect(hintText.style.fontSize, textStyle.fontSize); + }); + + testWidgets('InputField with specified hintStyle', (WidgetTester tester) async { + InputValue inputValue = InputValue.empty; + TextStyle hintStyle = new TextStyle( + color: Colors.pink[500], + fontSize: 10.0, + ); + + Widget builder() { + return new Center( + child: new Material( + child: new InputField( + value: inputValue, + hintText: 'Placeholder', + hintStyle: hintStyle, + ), + ), + ); + } + + await tester.pumpWidget(builder()); + + Text hintText = tester.widget(find.text('Placeholder')); + expect(hintText.style, hintStyle); + }); + testWidgets('Input label text animates', (WidgetTester tester) async { GlobalKey inputKey = new GlobalKey(); GlobalKey focusKey = new GlobalKey();