-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfocus_node.dart
52 lines (43 loc) · 1.09 KB
/
focus_node.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
part of flutter_extended_text_field;
class SelectableFocusNode extends FocusNode {
SelectableFocusNode([this.allowFocus = true]) : super();
final bool allowFocus;
}
class ExtendedFocusNode extends FocusNode {
ExtendedFocusNode([this.keyboardToken = true]) : super();
bool keyboardToken;
// @override
// bool get hasFocus => _hasFocus;
@override
bool consumeKeyboardToken() {
return keyboardToken;
}
void hideKeyboard() {
SystemChannels.textInput.invokeMethod<void>('TextInput.hide');
}
void showKeyboard() {
SystemChannels.textInput.invokeMethod<void>('TextInput.show');
}
@override
void unfocus({
UnfocusDisposition disposition = UnfocusDisposition.scope,
bool showCursor = false,
}) {
keyboardToken = false;
if (showCursor) {
hideKeyboard();
} else {
super.unfocus(disposition: disposition);
}
}
@override
void requestFocus([FocusNode? node, bool keyboard = true]) {
keyboardToken = keyboard;
if (keyboardToken) {
showKeyboard();
} else {
hideKeyboard();
}
super.requestFocus();
}
}