mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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:
parent
933323488b
commit
1ad0db51ae
@ -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,
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user