Cupertino TextField Cursor Fix (#27697)
* Fix for #26261. Changes CupertinoTextField's cursorColor to read from CupertinoTheme instead of prior default of activeBlue. CursorColor will still default to activeBlue for light theme and activeOrange for dark theme if a primary color has not been specified for the CupertinoTheme. * Reverted unnecessary changes in XCode file. * Updated text_field.dart per suggestions from @gspencergoog * Updated comments for cursorColor to reflect appropriate hyperlinks per @Hixie * Simplified cursorColor assignment per @xster * Added test in cupertino/text_field_test.dart to check for correct cursorColor based on CupertinoTheme per @Hixie & @xster.
This commit is contained in:
parent
c633e02853
commit
c58e31a74f
@ -172,7 +172,7 @@ class CupertinoTextField extends StatefulWidget {
|
|||||||
this.enabled,
|
this.enabled,
|
||||||
this.cursorWidth = 2.0,
|
this.cursorWidth = 2.0,
|
||||||
this.cursorRadius = const Radius.circular(2.0),
|
this.cursorRadius = const Radius.circular(2.0),
|
||||||
this.cursorColor = CupertinoColors.activeBlue,
|
this.cursorColor,
|
||||||
this.keyboardAppearance,
|
this.keyboardAppearance,
|
||||||
this.scrollPadding = const EdgeInsets.all(20.0),
|
this.scrollPadding = const EdgeInsets.all(20.0),
|
||||||
}) : assert(textAlign != null),
|
}) : assert(textAlign != null),
|
||||||
@ -365,7 +365,9 @@ class CupertinoTextField extends StatefulWidget {
|
|||||||
|
|
||||||
/// The color to use when painting the cursor.
|
/// The color to use when painting the cursor.
|
||||||
///
|
///
|
||||||
/// Defaults to the standard iOS blue color. Cannot be null.
|
/// Defaults to the [CupertinoThemeData.primaryColor] of the ambient theme,
|
||||||
|
/// which itself defaults to [CupertinoColors.activeBlue] in the light theme
|
||||||
|
/// and [CupertinoColors.activeOrange] in the dark theme.
|
||||||
final Color cursorColor;
|
final Color cursorColor;
|
||||||
|
|
||||||
/// The appearance of the keyboard.
|
/// The appearance of the keyboard.
|
||||||
@ -401,6 +403,7 @@ class CupertinoTextField extends StatefulWidget {
|
|||||||
properties.add(IntProperty('maxLines', maxLines, defaultValue: 1));
|
properties.add(IntProperty('maxLines', maxLines, defaultValue: 1));
|
||||||
properties.add(IntProperty('maxLength', maxLength, defaultValue: null));
|
properties.add(IntProperty('maxLength', maxLength, defaultValue: null));
|
||||||
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced'));
|
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced'));
|
||||||
|
properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor, defaultValue: null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,7 +647,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
|
|||||||
rendererIgnoresPointer: true,
|
rendererIgnoresPointer: true,
|
||||||
cursorWidth: widget.cursorWidth,
|
cursorWidth: widget.cursorWidth,
|
||||||
cursorRadius: widget.cursorRadius,
|
cursorRadius: widget.cursorRadius,
|
||||||
cursorColor: widget.cursorColor,
|
cursorColor: themeData.primaryColor,
|
||||||
cursorOpacityAnimates: true,
|
cursorOpacityAnimates: true,
|
||||||
cursorOffset: cursorOffset,
|
cursorOffset: cursorOffset,
|
||||||
paintCursorAboveText: true,
|
paintCursorAboveText: true,
|
||||||
|
@ -1345,4 +1345,46 @@ void main() {
|
|||||||
expect(setClient.method, 'TextInput.setClient');
|
expect(setClient.method, 'TextInput.setClient');
|
||||||
expect(setClient.arguments.last['keyboardAppearance'], 'Brightness.light');
|
expect(setClient.arguments.last['keyboardAppearance'], 'Brightness.light');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('cursorColor respects theme', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const CupertinoApp(
|
||||||
|
home: CupertinoTextField(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Finder textFinder = find.byType(CupertinoTextField);
|
||||||
|
await tester.tap(textFinder);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
final EditableTextState editableTextState =
|
||||||
|
tester.firstState(find.byType(EditableText));
|
||||||
|
final RenderEditable renderEditable = editableTextState.renderEditable;
|
||||||
|
|
||||||
|
expect(renderEditable.cursorColor, CupertinoColors.activeBlue);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const CupertinoApp(
|
||||||
|
home: CupertinoTextField(),
|
||||||
|
theme: CupertinoThemeData(
|
||||||
|
brightness: Brightness.dark,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pump();
|
||||||
|
expect(renderEditable.cursorColor, CupertinoColors.activeOrange);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const CupertinoApp(
|
||||||
|
home: CupertinoTextField(),
|
||||||
|
theme: CupertinoThemeData(
|
||||||
|
primaryColor: Color(0xFFF44336),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pump();
|
||||||
|
expect(renderEditable.cursorColor, const Color(0xFFF44336));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user