From af4f772b8abdf7c51c728b5459ba5f875a7770a9 Mon Sep 17 00:00:00 2001 From: open-trade Date: Fri, 27 Nov 2020 11:56:14 +0800 Subject: [PATCH] fix keyboard show/hide/show/hide for the first time click on keyboard button after password dialog --- flutter_hbb/lib/remote_page.dart | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index b883dba5e..0d7f2a9c4 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -34,6 +34,7 @@ class _RemotePageState extends State { var _more = false; var _fn = false; final FocusNode _focusNode = FocusNode(); + var _showEdit = true; @override void initState() { @@ -130,11 +131,20 @@ class _RemotePageState extends State { color: Colors.white, icon: Icon(Icons.keyboard), onPressed: () { - SystemChrome.setEnabledSystemUIOverlays( - SystemUiOverlay.values); - _focusNode.requestFocus(); - SystemChannels.textInput - .invokeMethod('TextInput.show'); + // destroy first, so that our _value trick can work + setState(() => _showEdit = false); + 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(Duration(milliseconds: 30), () { + SystemChrome.setEnabledSystemUIOverlays( + SystemUiOverlay.values); + _focusNode.requestFocus(); + SystemChannels.textInput + .invokeMethod('TextInput.show'); + }); + }); }), IconButton( color: Colors.white, @@ -231,7 +241,7 @@ class _RemotePageState extends State { SizedBox( width: 0, height: 0, - child: _bottom < 100 + child: !_showEdit ? Container() : TextFormField( textInputAction: TextInputAction.newline,