private RawInputKeyResponse GlobalKeyEventHandler( RawKeyEvent rawKeyEvent, bool enableCustomAction) { var keyCode = rawKeyEvent.data.unityEvent.keyCode; if (keyCode == KeyCode.UpArrow) { if (enableCustomAction) { MentionPopup.currentState.SelectPrev(); } return(RawInputKeyResponse.swallowResponse); } if (keyCode == KeyCode.DownArrow) { if (enableCustomAction) { MentionPopup.currentState.SelectNext(); } return(RawInputKeyResponse.swallowResponse); } if (rawKeyEvent.data.unityEvent.character == '\n' || rawKeyEvent.data.unityEvent.character == '\r' || rawKeyEvent.data.unityEvent.character == 3 || rawKeyEvent.data.unityEvent.character == 10) { if (MentionPopup.currentState.selectedIndex == -1 || !MentionPopup.currentState.isMentioning) { if (rawKeyEvent.data.unityEvent.shift) { return(new RawInputKeyResponse(true, '\n', TextInputAction.newline)); } else { if (enableCustomAction) { OnSubmitted(m_TextEditingController.text); return(RawInputKeyResponse.swallowResponse); } } } else { if (enableCustomAction) { MentionPopup.currentState.Select(); } return(RawInputKeyResponse.swallowResponse); } } return(RawInputKeyResponse.convert(rawKeyEvent)); }
List <Widget> buildInputs(bool unityKeyboard) { List <Widget> widgets = new List <Widget>(); var style = new TextStyle(); var cursorColor = new Color(0xFF000000); var selectionColor = new Color(0xFF6F6F6F); widgets.Add(this.rowWidgets("Default", new EditStateProvider(builder: ((buildContext, controller, node) => new EditableText(controller, node, style, cursorColor: cursorColor, backgroundCursorColor: Colors.blue, selectionColor: selectionColor, onSubmitted: this.textSubmitted , unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls, cursorWidth: 5.0f, cursorRadius: Radius.circular(2.5f), cursorOpacityAnimates: true, paintCursorAboveText: true))))); widgets.Add(this.rowWidgets("Multiple Line", new EditStateProvider( builder: ((buildContext, controller, node) => new EditableText(controller, node, style, cursorColor: cursorColor, backgroundCursorColor: Colors.transparent, selectionColor: selectionColor, maxLines: 4, onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls, globalKeyEventHandler: (evt, enableCustomAction) => { //customized key event handler which may swallow input keys to the editable and //perform customized functionality // //evt is the input rawKeyEvent //you should perform any customized functionality within the closure of "if(enableCustomAction) {}", //otherwise it could be performed multiple times for a single key event. // //Very Important: for any input event, please ensure that all the output RawInputKeyResponse is the same //regardless of the value of enableCustomAction, otherwise the behavior of this handler would become //wrong and unpredictable if (evt.data.unityEvent.keyCode == KeyCode.UpArrow) { if (enableCustomAction) { Debug.Log("UpUpUp"); } return(RawInputKeyResponse.swallowResponse); } if (evt.data.unityEvent.keyCode == KeyCode.DownArrow) { if (enableCustomAction) { Debug.Log("UpUpUp"); } return(RawInputKeyResponse.swallowResponse); } if (evt.data.unityEvent.character == '\n' || evt.data.unityEvent.character == '\r' || evt.data.unityEvent.character == 3 || evt.data.unityEvent.character == 10) { if (evt.data.unityEvent.shift) { if (enableCustomAction) { Debug.Log("shift return >>>"); } return(new RawInputKeyResponse(true, evt.data.unityEvent.character, inputAction: TextInputAction.newline)); } else { if (enableCustomAction) { Debug.Log("send !!!!"); } return(RawInputKeyResponse.swallowResponse); } } return(RawInputKeyResponse.convert(evt)); }))))); widgets.Add(this.rowWidgets("ObscureText", new EditStateProvider( builder: ((buildContext, controller, node) => new EditableText(controller, node, style, cursorColor: cursorColor, backgroundCursorColor: Colors.transparent, selectionColor: selectionColor, obscureText: true, onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls))))); widgets.Add(this.rowWidgets("Number", new EditStateProvider(builder: ((buildContext, controller, node) => new EditableText(controller, node, style, cursorColor: cursorColor, backgroundCursorColor: Colors.transparent, selectionColor: selectionColor, keyboardType: TextInputType.number, onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls))))); widgets.Add(this.rowWidgets("Phone", new EditStateProvider(builder: ((buildContext, controller, node) => new EditableText(controller, node, style, cursorColor: cursorColor, backgroundCursorColor: Colors.transparent, selectionColor: selectionColor, keyboardType: TextInputType.phone, onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls))))); widgets.Add(this.rowWidgets("Email", new EditStateProvider(builder: ((buildContext, controller, node) => new EditableText(controller, node, style, cursorColor: cursorColor, backgroundCursorColor: Colors.transparent, selectionColor: selectionColor, keyboardType: TextInputType.emailAddress, onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls))))); widgets.Add(this.rowWidgets("Url", new EditStateProvider(builder: ((buildContext, controller, node) => new EditableText(controller, node, style, cursorColor: cursorColor, backgroundCursorColor: Colors.transparent, selectionColor: selectionColor, keyboardType: TextInputType.url, onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls))))); return(widgets); }