Added cusor control properties to CupertinoSearchTextField and tests (#158240)

Adding control over the cursor to CupertinoSearchTextField: cursorWidth, cursorHeight, cursorRadius, cursorOpacityAnimates and cursorColor.

fixes https://github.com/flutter/flutter/issues/158239
This commit is contained in:
Paul Salmon 2024-11-07 00:04:55 +01:00 committed by GitHub
parent 933323488b
commit 1ad0db51ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 100 additions and 0 deletions

View File

@ -133,6 +133,11 @@ class CupertinoSearchTextField extends StatefulWidget {
this.onTap,
this.autocorrect = true,
this.enabled,
this.cursorWidth = 2.0,
this.cursorHeight,
this.cursorRadius = const Radius.circular(2.0),
this.cursorOpacityAnimates = true,
this.cursorColor,
}) : assert(
!((decoration != null) && (backgroundColor != null)),
'Cannot provide both a background color and a decoration\n'
@ -327,6 +332,21 @@ class CupertinoSearchTextField extends StatefulWidget {
/// respond to touch events including the [prefixIcon] and [suffixIcon] button.
final bool? enabled;
/// {@macro flutter.widgets.editableText.cursorWidth}
final double cursorWidth;
/// {@macro flutter.widgets.editableText.cursorHeight}
final double? cursorHeight;
/// {@macro flutter.widgets.editableText.cursorRadius}
final Radius cursorRadius;
/// {@macro flutter.widgets.editableText.cursorOpacityAnimates}
final bool cursorOpacityAnimates;
/// The color to use when painting the cursor.
final Color? cursorColor;
@override
State<StatefulWidget> createState() => _CupertinoSearchTextFieldState();
}
@ -514,6 +534,11 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
keyboardType: widget.keyboardType,
onTap: widget.onTap,
enabled: widget.enabled ?? true,
cursorWidth: widget.cursorWidth,
cursorHeight: widget.cursorHeight,
cursorRadius: widget.cursorRadius,
cursorOpacityAnimates: widget.cursorOpacityAnimates,
cursorColor: widget.cursorColor,
suffixMode: widget.suffixMode,
placeholder: placeholder,
placeholderStyle: placeholderStyle,

View File

@ -655,6 +655,81 @@ void main() {
expect(textField.enableIMEPersonalizedLearning, false);
});
testWidgets('cursorWidth is properly forwarded to the inner text field', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
cursorWidth: 1,
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.cursorWidth, 1);
});
testWidgets('cursorHeight is properly forwarded to the inner text field', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
cursorHeight: 10,
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.cursorHeight, 10);
});
testWidgets('cursorRadius is properly forwarded to the inner text field', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
cursorRadius: Radius.circular(1.0),
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.cursorRadius, const Radius.circular(1.0));
});
testWidgets('cursorOpacityAnimates is properly forwarded to the inner text field', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
cursorOpacityAnimates: false,
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.cursorOpacityAnimates, false);
});
testWidgets('cursorColor is properly forwarded to the inner text field', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
cursorColor: Color.fromARGB(255, 255, 0, 0),
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.cursorColor, const Color.fromARGB(255, 255, 0, 0));
});
testWidgets('Icons and placeholder fade while resizing on scroll', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(