Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: sky/framework/components/input.dart

Issue 1002453003: Make Stocks app search actually search (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/examples/stocks-fn/stocksapp.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 left: 8px; 28 left: 8px;
29 color: ${Grey[200]}; 29 color: ${Grey[200]};
30 position: absolute;''' 30 position: absolute;'''
31 ); 31 );
32 32
33 static final String _focusedInlineStyle = ''' 33 static final String _focusedInlineStyle = '''
34 padding: 7px; 34 padding: 7px;
35 border-bottom: 2px solid ${Blue[500]};'''; 35 border-bottom: 2px solid ${Blue[500]};''';
36 36
37 ValueChanged onChanged; 37 ValueChanged onChanged;
38 String value;
39 String placeholder; 38 String placeholder;
40 bool focused = false; 39 bool focused = false;
41 40
41 String _value = '';
42 bool _isAttachedToKeyboard = false; 42 bool _isAttachedToKeyboard = false;
43 EditableString _editableValue; 43 EditableString _editableValue;
44 44
45 Input({Object key, this.value: '', this.placeholder, this.focused}) 45 Input({Object key,
46 this.placeholder,
47 this.onChanged,
48 this.focused})
46 : super(key: key, stateful: true) { 49 : super(key: key, stateful: true) {
47 _editableValue = new EditableString(text: value, 50 _editableValue = new EditableString(text: _value,
48 onUpdated: _handleTextUpdated); 51 onUpdated: _handleTextUpdated);
49 } 52 }
50 53
51 void _handleTextUpdated() { 54 void _handleTextUpdated() {
52 setState(() {}); 55 setState(() {});
53 if (value != _editableValue.text) { 56 if (_value != _editableValue.text) {
54 value = _editableValue.text; 57 _value = _editableValue.text;
55 if (onChanged != null) 58 if (onChanged != null)
56 onChanged(value); 59 onChanged(_value);
57 } 60 }
58 } 61 }
59 62
60 void didUnmount() { 63 void didUnmount() {
61 if (_isAttachedToKeyboard) 64 if (_isAttachedToKeyboard)
62 keyboard.hide(); 65 keyboard.hide();
63 } 66 }
64 67
65 Node build() { 68 Node build() {
66 if (focused && !_isAttachedToKeyboard) { 69 if (focused && !_isAttachedToKeyboard) {
67 keyboard.show(_editableValue.stub); 70 keyboard.show(_editableValue.stub);
68 _isAttachedToKeyboard = true; 71 _isAttachedToKeyboard = true;
69 } 72 }
70 73
71 List<Node> children = []; 74 List<Node> children = [];
72 75
73 if (placeholder != null && value.isEmpty) { 76 if (placeholder != null && _value.isEmpty) {
74 children.add(new Container( 77 children.add(new Container(
75 style: _placeholderStyle, 78 style: _placeholderStyle,
76 children: [new Text(placeholder)] 79 children: [new Text(placeholder)]
77 )); 80 ));
78 } 81 }
79 82
80 children.add(new EditableText(value: _editableValue, focused: focused)); 83 children.add(new EditableText(value: _editableValue, focused: focused));
81 84
82 return new Container( 85 return new Container(
83 style: _style, 86 style: _style,
84 inlineStyle: focused ? _focusedInlineStyle : null, 87 inlineStyle: focused ? _focusedInlineStyle : null,
85 children: children 88 children: children
86 ); 89 );
87 } 90 }
88 } 91 }
OLDNEW
« no previous file with comments | « sky/examples/stocks-fn/stocksapp.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698