use flutter_keyboard_visibility
This commit is contained in:
parent
3cc0c1df69
commit
9fb5b2cb5f
@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:flutter_hbb/consts.dart';
|
import 'package:flutter_hbb/consts.dart';
|
||||||
import 'package:flutter_hbb/mobile/widgets/gesture_help.dart';
|
import 'package:flutter_hbb/mobile/widgets/gesture_help.dart';
|
||||||
import 'package:flutter_hbb/models/chat_model.dart';
|
import 'package:flutter_hbb/models/chat_model.dart';
|
||||||
|
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
|
||||||
import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';
|
import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:wakelock/wakelock.dart';
|
import 'package:wakelock/wakelock.dart';
|
||||||
@ -33,10 +34,8 @@ class RemotePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _RemotePageState extends State<RemotePage> {
|
class _RemotePageState extends State<RemotePage> {
|
||||||
Timer? _interval;
|
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
bool _showBar = !isWebDesktop;
|
bool _showBar = !isWebDesktop;
|
||||||
double _bottom = 0;
|
|
||||||
String _value = '';
|
String _value = '';
|
||||||
double _scale = 1;
|
double _scale = 1;
|
||||||
double _mouseScrollIntegral = 0; // mouse scroll speed controller
|
double _mouseScrollIntegral = 0; // mouse scroll speed controller
|
||||||
@ -44,6 +43,8 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
|
|
||||||
var _more = true;
|
var _more = true;
|
||||||
var _fn = false;
|
var _fn = false;
|
||||||
|
late final keyboardVisibilityController = KeyboardVisibilityController();
|
||||||
|
late final StreamSubscription<bool> keyboardSubscription;
|
||||||
final FocusNode _mobileFocusNode = FocusNode();
|
final FocusNode _mobileFocusNode = FocusNode();
|
||||||
final FocusNode _physicalFocusNode = FocusNode();
|
final FocusNode _physicalFocusNode = FocusNode();
|
||||||
var _showEdit = false; // use soft keyboard
|
var _showEdit = false; // use soft keyboard
|
||||||
@ -58,14 +59,14 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
|
||||||
gFFI.dialogManager
|
gFFI.dialogManager
|
||||||
.showLoading(translate('Connecting...'), onCancel: closeConnection);
|
.showLoading(translate('Connecting...'), onCancel: closeConnection);
|
||||||
_interval =
|
|
||||||
Timer.periodic(Duration(milliseconds: 30), (timer) => interval());
|
|
||||||
});
|
});
|
||||||
Wakelock.enable();
|
Wakelock.enable();
|
||||||
_physicalFocusNode.requestFocus();
|
_physicalFocusNode.requestFocus();
|
||||||
gFFI.ffiModel.updateEventListener(widget.id);
|
gFFI.ffiModel.updateEventListener(widget.id);
|
||||||
gFFI.inputModel.listenToMouse(true);
|
gFFI.inputModel.listenToMouse(true);
|
||||||
gFFI.qualityMonitorModel.checkShowQualityMonitor(widget.id);
|
gFFI.qualityMonitorModel.checkShowQualityMonitor(widget.id);
|
||||||
|
keyboardSubscription =
|
||||||
|
keyboardVisibilityController.onChange.listen(onSoftKeyboardChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -76,49 +77,27 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
_mobileFocusNode.dispose();
|
_mobileFocusNode.dispose();
|
||||||
_physicalFocusNode.dispose();
|
_physicalFocusNode.dispose();
|
||||||
gFFI.close();
|
gFFI.close();
|
||||||
_interval?.cancel();
|
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
gFFI.dialogManager.dismissAll();
|
gFFI.dialogManager.dismissAll();
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
||||||
overlays: SystemUiOverlay.values);
|
overlays: SystemUiOverlay.values);
|
||||||
Wakelock.disable();
|
Wakelock.disable();
|
||||||
|
keyboardSubscription.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetTool() {
|
void onSoftKeyboardChanged(bool visible) {
|
||||||
inputModel.resetModifiers();
|
inputModel.resetModifiers();
|
||||||
}
|
if (!visible) {
|
||||||
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
|
||||||
bool isKeyboardShown() {
|
// [pi.version.isNotEmpty] -> check ready or not, avoid login without soft-keyboard
|
||||||
return _bottom >= 100;
|
if (gFFI.chatModel.chatWindowOverlayEntry == null &&
|
||||||
}
|
gFFI.ffiModel.pi.version.isNotEmpty) {
|
||||||
|
gFFI.invokeMethod("enable_soft_keyboard", false);
|
||||||
// crash on web before widget initiated.
|
}
|
||||||
void intervalUnsafe() {
|
|
||||||
var v = MediaQuery.of(context).viewInsets.bottom;
|
|
||||||
if (v != _bottom) {
|
|
||||||
resetTool();
|
|
||||||
setState(() {
|
|
||||||
_bottom = v;
|
|
||||||
if (v < 100) {
|
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
|
||||||
overlays: []);
|
|
||||||
// [pi.version.isNotEmpty] -> check ready or not, avoid login without soft-keyboard
|
|
||||||
if (gFFI.chatModel.chatWindowOverlayEntry == null &&
|
|
||||||
gFFI.ffiModel.pi.version.isNotEmpty) {
|
|
||||||
gFFI.invokeMethod("enable_soft_keyboard", false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void interval() {
|
|
||||||
try {
|
|
||||||
intervalUnsafe();
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle mobile virtual keyboard
|
// handle mobile virtual keyboard
|
||||||
void handleSoftKeyboardInput(String newValue) {
|
void handleSoftKeyboardInput(String newValue) {
|
||||||
var oldValue = _value;
|
var oldValue = _value;
|
||||||
@ -219,8 +198,9 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final pi = Provider.of<FfiModel>(context).pi;
|
final pi = Provider.of<FfiModel>(context).pi;
|
||||||
final hideKeyboard = isKeyboardShown() && _showEdit;
|
final isHideKeyboardFAB =
|
||||||
final showActionButton = !_showBar || hideKeyboard;
|
keyboardVisibilityController.isVisible && _showEdit;
|
||||||
|
final showActionButton = !_showBar || isHideKeyboardFAB;
|
||||||
final keyboard = gFFI.ffiModel.permissions['keyboard'] != false;
|
final keyboard = gFFI.ffiModel.permissions['keyboard'] != false;
|
||||||
|
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
@ -230,21 +210,21 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
},
|
},
|
||||||
child: getRawPointerAndKeyBody(Scaffold(
|
child: getRawPointerAndKeyBody(Scaffold(
|
||||||
// workaround for https://github.com/rustdesk/rustdesk/issues/3131
|
// workaround for https://github.com/rustdesk/rustdesk/issues/3131
|
||||||
floatingActionButtonLocation: hideKeyboard
|
floatingActionButtonLocation: isHideKeyboardFAB
|
||||||
? FABLocation(FloatingActionButtonLocation.endFloat, 0, -35)
|
? FABLocation(FloatingActionButtonLocation.endFloat, 0, -35)
|
||||||
: null,
|
: null,
|
||||||
floatingActionButton: !showActionButton
|
floatingActionButton: !showActionButton
|
||||||
? null
|
? null
|
||||||
: FloatingActionButton(
|
: FloatingActionButton(
|
||||||
mini: !hideKeyboard,
|
mini: !isHideKeyboardFAB,
|
||||||
child: Icon(
|
child: Icon(
|
||||||
hideKeyboard ? Icons.expand_more : Icons.expand_less,
|
isHideKeyboardFAB ? Icons.expand_more : Icons.expand_less,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
backgroundColor: MyTheme.accent,
|
backgroundColor: MyTheme.accent,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (hideKeyboard) {
|
if (isHideKeyboardFAB) {
|
||||||
_showEdit = false;
|
_showEdit = false;
|
||||||
gFFI.invokeMethod("enable_soft_keyboard", false);
|
gFFI.invokeMethod("enable_soft_keyboard", false);
|
||||||
_mobileFocusNode.unfocus();
|
_mobileFocusNode.unfocus();
|
||||||
@ -725,7 +705,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
Widget getHelpTools() {
|
Widget getHelpTools() {
|
||||||
final keyboard = isKeyboardShown();
|
final keyboard = keyboardVisibilityController.isVisible;
|
||||||
if (!keyboard) {
|
if (!keyboard) {
|
||||||
return SizedBox();
|
return SizedBox();
|
||||||
}
|
}
|
||||||
@ -858,9 +838,10 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
spacing: space,
|
spacing: space,
|
||||||
runSpacing: space,
|
runSpacing: space,
|
||||||
children: <Widget>[SizedBox(width: 9999)] +
|
children: <Widget>[SizedBox(width: 9999)] +
|
||||||
(keyboard
|
modifiers +
|
||||||
? modifiers + keys + (_fn ? fn : []) + (_more ? more : [])
|
keys +
|
||||||
: modifiers),
|
(_fn ? fn : []) +
|
||||||
|
(_more ? more : []),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,6 +488,54 @@ packages:
|
|||||||
url: "https://github.com/Kingtous/flutter_improved_scrolling"
|
url: "https://github.com/Kingtous/flutter_improved_scrolling"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.3"
|
version: "0.0.3"
|
||||||
|
flutter_keyboard_visibility:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_keyboard_visibility
|
||||||
|
sha256: "86b71bbaffa38e885f5c21b1182408b9be6951fd125432cf6652c636254cef2d"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.4.0"
|
||||||
|
flutter_keyboard_visibility_linux:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: flutter_keyboard_visibility_linux
|
||||||
|
sha256: "6fba7cd9bb033b6ddd8c2beb4c99ad02d728f1e6e6d9b9446667398b2ac39f08"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
|
flutter_keyboard_visibility_macos:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: flutter_keyboard_visibility_macos
|
||||||
|
sha256: c5c49b16fff453dfdafdc16f26bdd8fb8d55812a1d50b0ce25fc8d9f2e53d086
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
|
flutter_keyboard_visibility_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: flutter_keyboard_visibility_platform_interface
|
||||||
|
sha256: e43a89845873f7be10cb3884345ceb9aebf00a659f479d1c8f4293fcb37022a4
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0"
|
||||||
|
flutter_keyboard_visibility_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: flutter_keyboard_visibility_web
|
||||||
|
sha256: d3771a2e752880c79203f8d80658401d0c998e4183edca05a149f5098ce6e3d1
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0"
|
||||||
|
flutter_keyboard_visibility_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: flutter_keyboard_visibility_windows
|
||||||
|
sha256: fc4b0f0b6be9b93ae527f3d527fb56ee2d918cd88bbca438c478af7bcfd0ef73
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
flutter_launcher_icons:
|
flutter_launcher_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -91,6 +91,7 @@ dependencies:
|
|||||||
win32: any
|
win32: any
|
||||||
password_strength: ^0.2.0
|
password_strength: ^0.2.0
|
||||||
flutter_launcher_icons: ^0.11.0
|
flutter_launcher_icons: ^0.11.0
|
||||||
|
flutter_keyboard_visibility: ^5.4.0
|
||||||
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user