| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import '../editing/editable_string.dart'; | 5 import '../editing/editable_string.dart'; |
| 6 import '../editing/editable_text.dart'; | 6 import '../editing/editable_text.dart'; |
| 7 import '../editing/keyboard.dart'; | 7 import '../editing/keyboard.dart'; |
| 8 import '../fn.dart'; | 8 import '../fn.dart'; |
| 9 import '../theme/colors.dart'; | 9 import '../theme/colors.dart'; |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 white-space: pre; | 21 white-space: pre; |
| 22 overflow: hidden;''' | 22 overflow: hidden;''' |
| 23 ); | 23 ); |
| 24 | 24 |
| 25 static final String _focusedInlineStyle = ''' | 25 static final String _focusedInlineStyle = ''' |
| 26 padding: 7px; | 26 padding: 7px; |
| 27 border-bottom: 2px solid ${Blue[500]};'''; | 27 border-bottom: 2px solid ${Blue[500]};'''; |
| 28 | 28 |
| 29 ValueChanged onChanged; | 29 ValueChanged onChanged; |
| 30 String value; | 30 String value; |
| 31 bool focused = false; |
| 31 | 32 |
| 32 bool _focused = false; | 33 bool _isAttachedToKeyboard = false; |
| 33 EditableString _editableValue; | 34 EditableString _editableValue; |
| 34 | 35 |
| 35 Input({Object key, this.value: ''}) : super(key: key, stateful: true) { | 36 Input({Object key, this.value: '', this.focused}) |
| 37 : super(key: key, stateful: true) { |
| 36 _editableValue = new EditableString(text: value, | 38 _editableValue = new EditableString(text: value, |
| 37 onUpdated: _handleTextUpdated); | 39 onUpdated: _handleTextUpdated); |
| 38 events.listen('click', _handleClick); | |
| 39 } | |
| 40 | |
| 41 void _handleClick(_) { | |
| 42 keyboard.show(_editableValue.stub); | |
| 43 setState(() { | |
| 44 _focused = true; | |
| 45 }); | |
| 46 } | 40 } |
| 47 | 41 |
| 48 void _handleTextUpdated() { | 42 void _handleTextUpdated() { |
| 49 setState(() {}); | 43 setState(() {}); |
| 50 if (value != _editableValue.text) { | 44 if (value != _editableValue.text) { |
| 51 value = _editableValue.text; | 45 value = _editableValue.text; |
| 52 if (onChanged != null) | 46 if (onChanged != null) |
| 53 onChanged(value); | 47 onChanged(value); |
| 54 } | 48 } |
| 55 } | 49 } |
| 56 | 50 |
| 51 void didUnmount() { |
| 52 if (_isAttachedToKeyboard) |
| 53 keyboard.hide(); |
| 54 } |
| 55 |
| 57 Node build() { | 56 Node build() { |
| 57 if (focused && !_isAttachedToKeyboard) { |
| 58 keyboard.show(_editableValue.stub); |
| 59 _isAttachedToKeyboard = true; |
| 60 } |
| 61 |
| 58 return new Container( | 62 return new Container( |
| 59 style: _style, | 63 style: _style, |
| 60 inlineStyle: _focused ? _focusedInlineStyle : null, | 64 inlineStyle: focused ? _focusedInlineStyle : null, |
| 61 children: [ | 65 children: [ |
| 62 new EditableText(value: _editableValue, focused: _focused), | 66 new EditableText(value: _editableValue, focused: focused), |
| 63 ] | 67 ] |
| 64 ); | 68 ); |
| 65 } | 69 } |
| 66 } | 70 } |
| OLD | NEW |