better input
This commit is contained in:
parent
fa78e7b291
commit
722a382ce2
@ -9,6 +9,8 @@ import 'package:wakelock/wakelock.dart';
|
|||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
|
|
||||||
|
final initText = '\1' * 1024;
|
||||||
|
|
||||||
class RemotePage extends StatefulWidget {
|
class RemotePage extends StatefulWidget {
|
||||||
RemotePage({Key key, this.id}) : super(key: key);
|
RemotePage({Key key, this.id}) : super(key: key);
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_value = ' ' * 1000;
|
_value = initText;
|
||||||
FFI.connect(widget.id);
|
FFI.connect(widget.id);
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
SystemChrome.setEnabledSystemUIOverlays([]);
|
SystemChrome.setEnabledSystemUIOverlays([]);
|
||||||
@ -56,9 +58,9 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_focusNode.dispose();
|
_focusNode.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
FFI.close();
|
||||||
_interval.cancel();
|
_interval.cancel();
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
FFI.close();
|
|
||||||
dismissLoading();
|
dismissLoading();
|
||||||
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
|
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
|
||||||
Wakelock.disable();
|
Wakelock.disable();
|
||||||
@ -73,7 +75,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
var v = MediaQuery.of(context).viewInsets.bottom;
|
var v = MediaQuery.of(context).viewInsets.bottom;
|
||||||
if (v != _bottom) {
|
if (v != _bottom) {
|
||||||
resetTool();
|
resetTool();
|
||||||
_value = ' ' * 1000;
|
_value = initText;
|
||||||
setState(() {
|
setState(() {
|
||||||
_bottom = v;
|
_bottom = v;
|
||||||
if (v < 100) {
|
if (v < 100) {
|
||||||
@ -115,6 +117,46 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleInput(String newValue) {
|
||||||
|
if (_value[0] == '\1' && newValue[0] != '\1') {
|
||||||
|
// clipboard
|
||||||
|
_value = '';
|
||||||
|
}
|
||||||
|
if (newValue.length <= _value.length) {
|
||||||
|
final char = 'VK_BACK';
|
||||||
|
FFI.inputKey(char);
|
||||||
|
} else {
|
||||||
|
final content = newValue.substring(_value.length);
|
||||||
|
if (content.length > 1) {
|
||||||
|
FFI.setByName('input_string', content);
|
||||||
|
} else {
|
||||||
|
var char = content;
|
||||||
|
if (char == '\n') {
|
||||||
|
char = 'VK_RETURN';
|
||||||
|
}
|
||||||
|
FFI.inputKey(char);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_value = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void openKeyboard() {
|
||||||
|
// destroy first, so that our _value trick can work
|
||||||
|
setState(() => _showEdit = false);
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = Timer(Duration(milliseconds: 30), () {
|
||||||
|
// show now, and sleep a while to requestFocus to
|
||||||
|
// make sure edit ready, so that keyboard wont show/hide/show/hide happen
|
||||||
|
setState(() => _showEdit = true);
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = Timer(Duration(milliseconds: 30), () {
|
||||||
|
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
|
||||||
|
SystemChannels.textInput.invokeMethod('TextInput.show');
|
||||||
|
_focusNode.requestFocus();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
EasyLoading.instance.loadingStyle = EasyLoadingStyle.light;
|
EasyLoading.instance.loadingStyle = EasyLoadingStyle.light;
|
||||||
@ -152,24 +194,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
icon: Icon(Icons.keyboard),
|
icon: Icon(Icons.keyboard),
|
||||||
onPressed: () {
|
onPressed: openKeyboard),
|
||||||
// destroy first, so that our _value trick can work
|
|
||||||
setState(() => _showEdit = false);
|
|
||||||
_timer?.cancel();
|
|
||||||
_timer = Timer(Duration(milliseconds: 30), () {
|
|
||||||
// show now, and sleep a while to requestFocus to
|
|
||||||
// make sure edit ready, so that keyboard wont show/hide/show/hide happen
|
|
||||||
setState(() => _showEdit = true);
|
|
||||||
_timer?.cancel();
|
|
||||||
_timer = Timer(Duration(milliseconds: 30), () {
|
|
||||||
SystemChrome.setEnabledSystemUIOverlays(
|
|
||||||
SystemUiOverlay.values);
|
|
||||||
SystemChannels.textInput
|
|
||||||
.invokeMethod('TextInput.show');
|
|
||||||
_focusNode.requestFocus();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
icon: Icon(Icons.tv),
|
icon: Icon(Icons.tv),
|
||||||
@ -278,22 +303,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
initialValue:
|
initialValue:
|
||||||
_value, // trick way to make backspace work always
|
_value, // trick way to make backspace work always
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
onChanged: (x) {
|
onChanged: handleInput,
|
||||||
if (x.length <= _value.length) {
|
|
||||||
final char = 'VK_BACK';
|
|
||||||
FFI.inputKey(char);
|
|
||||||
}
|
|
||||||
for (var i = _value.length;
|
|
||||||
i < x.length;
|
|
||||||
++i) {
|
|
||||||
var char = x[i];
|
|
||||||
if (char == '\n') {
|
|
||||||
char = 'VK_RETURN';
|
|
||||||
}
|
|
||||||
FFI.inputKey(char);
|
|
||||||
}
|
|
||||||
_value = x;
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
])),
|
])),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user