Skip to content

Commit

Permalink
support cursorColor customization (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleunghk authored Dec 2, 2021
1 parent e9c6f14 commit 93ef75a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Hope you find it useful and happy coding! 🎉🎉🎉
| Name | Type | Description | Default |
|:----------------|:--------------|:-------------------------------|:-------------------------|
| `controller` | TextEditingController | Controlling the text being edited (https://api.flutter.dev/flutter/material/TextField/controller.html) | null |
| `decoration` | BoxDecoration | Controls the BoxDecoration of the box behind the text input. (https://api.flutter.dev/flutter/cupertino/CupertinoTextField/decoration.html) | null |
| `cursorColor` | Color | The color of the cursor (https://api.flutter.dev/flutter/material/TextField/cursorColor.html) | null | `decoration` | BoxDecoration | Controls the BoxDecoration of the box behind the text input. (https://api.flutter.dev/flutter/cupertino/CupertinoTextField/decoration.html) | null |
| `style` | TextStyle | The style to use for the text being edited [Only `fontSize`, `fontWeight`, `color` are supported] (https://api.flutter.dev/flutter/material/TextField/style.html) | null |
| `placeholderStyle`| TextStyle | The style to use for the placeholder text. [Only `fontSize`, `fontWeight`, `color` are supported] (https://api.flutter.dev/flutter/cupertino/CupertinoTextField/placeholderStyle.html) | null |
| `placeholder` | String | Placeholder text when text entry is empty (https://api.flutter.dev/flutter/cupertino/CupertinoTextField/placeholder.html) | null |
Expand All @@ -35,8 +35,8 @@ Hope you find it useful and happy coding! 🎉🎉🎉
| `onSubmitted` | ValueChanged\<String> | Called when the user indicates that they are done editing the text in the field (https://api.flutter.dev/flutter/material/TextField/onSubmitted.html) | null |
| `focusNode` | FocusNode | Defines the keyboard focus for this widget (https://api.flutter.dev/flutter/material/TextField/focusNode.html) | null |
| `textAlign` | TextAlign | How the text should be aligned horizontally (https://api.flutter.dev/flutter/material/TextField/textAlign.html) | TextAlign.start |
| `minLines` | int | Minimum number of lines of text input widget | 1 |
| `maxLines` | int | The maximum number of lines to show at one time, wrapping if necessary (https://api.flutter.dev/flutter/material/TextField/maxLines.html) | 1 |
| `minLines` | int | Minimum number of lines of text input widget | 1 |

## More examples

Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class HomePage extends StatelessWidget {
DemoItem(
title: 'Flutter CupertinoTextField Example Usage',
child: CupertinoTextField(
cursorColor: Colors.black87,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black87,
Expand All @@ -73,6 +74,7 @@ class HomePage extends StatelessWidget {
title: 'NativeTextInput Example Usage',
child: Platform.isIOS
? NativeTextInput(
cursorColor: Colors.black87,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black87,
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/NativeTextInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ - (instancetype)initWithFrame:(CGRect)frame
if (@available(iOS 10.0, *)) {
_textView.textContentType = [self textContentTypeFromString:args[@"textContentType"]];
}
if (args[@"cursorColor"] && ![args[@"cursorColor"] isKindOfClass:[NSNull class]]) {
NSDictionary* fontColor = args[@"cursorColor"];
_textView.tintColor = [UIColor colorWithRed:[fontColor[@"red"] floatValue]/255.0 green:[fontColor[@"green"] floatValue]/255.0 blue:[fontColor[@"blue"] floatValue]/255.0 alpha:[fontColor[@"alpha"] floatValue]/255.0];
}


_delegate = [[NativeTextInputDelegate alloc] initWithChannel:_channel arguments:args ];
_textView.delegate = _delegate;
Expand Down
17 changes: 16 additions & 1 deletion lib/flutter_native_text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class NativeTextInput extends StatefulWidget {
const NativeTextInput({
Key? key,
this.controller,
this.cursorColor,
this.decoration,
this.style,
this.placeholderStyle,
Expand All @@ -84,15 +85,17 @@ class NativeTextInput extends StatefulWidget {
this.onSubmitted,
this.focusNode,
this.textAlign = TextAlign.start,
this.minLines = 1,
this.maxLines = 1,
this.minLines = 1,
}) : super(key: key);

/// Controls the text being edited.
///
/// If null, this widget will create its own [TextEditingController].
final TextEditingController? controller;

final Color? cursorColor;

final BoxDecoration? decoration;

final TextStyle? style;
Expand Down Expand Up @@ -270,6 +273,18 @@ class _NativeTextInputState extends State<NativeTextInput> {
};
}

if (widget.cursorColor != null) {
params = {
...params,
"cursorColor": {
"red": widget.cursorColor?.red,
"green": widget.cursorColor?.green,
"blue": widget.cursorColor?.blue,
"alpha": widget.cursorColor?.alpha,
},
};
}

return params;
}

Expand Down

0 comments on commit 93ef75a

Please sign in to comment.