flutter_desktop: fix ffi model provider

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-08-06 18:48:07 +08:00
parent 0e012894b5
commit 917830fb69
2 changed files with 98 additions and 94 deletions

View File

@ -58,6 +58,8 @@ class _ConnectionPageState extends State<ConnectionPage> {
@override
Widget build(BuildContext context) {
Provider.of<FfiModel>(context);
if (_idController.text.isEmpty) _idController.text = gFFI.getId();
return Container(
decoration: BoxDecoration(color: isDarkTheme() ? null : MyTheme.grayBg),

View File

@ -236,15 +236,49 @@ class _RemotePageState extends State<RemotePage>
_ffi.inputKey(label, down: down, press: press ?? false);
}
Widget buildBody(FfiModel ffiModel) {
final hasDisplays = ffiModel.pi.displays.length > 0;
final hideKeyboard = isKeyboardShown() && _showEdit;
final showActionButton = !_showBar || hideKeyboard;
final keyboard = ffiModel.permissions['keyboard'] != false;
return Scaffold(
// resizeToAvoidBottomInset: true,
floatingActionButton: !showActionButton
? null
: FloatingActionButton(
mini: !hideKeyboard,
child:
Icon(hideKeyboard ? Icons.expand_more : Icons.expand_less),
backgroundColor: MyTheme.accent,
onPressed: () {
setState(() {
if (hideKeyboard) {
_showEdit = false;
_ffi.invokeMethod("enable_soft_keyboard", false);
_mobileFocusNode.unfocus();
_physicalFocusNode.requestFocus();
} else {
_showBar = !_showBar;
}
});
}),
bottomNavigationBar: _showBar && hasDisplays ? getBottomAppBar() : null,
body: Overlay(
initialEntries: [
OverlayEntry(builder: (context) {
return Container(
color: Colors.black,
child: getBodyForDesktopWithListener(keyboard));
})
],
));
}
@override
Widget build(BuildContext context) {
super.build(context);
Provider.of<CanvasModel>(context, listen: false).tabBarHeight =
super.widget.tabBarHeight;
final hasDisplays = _ffi.ffiModel.pi.displays.length > 0;
final hideKeyboard = isKeyboardShown() && _showEdit;
final showActionButton = !_showBar || hideKeyboard;
final keyboard = _ffi.ffiModel.permissions['keyboard'] != false;
return WillPopScope(
onWillPop: () async {
clientClose();
@ -257,47 +291,11 @@ class _RemotePageState extends State<RemotePage>
ChangeNotifierProvider.value(value: _ffi.cursorModel),
ChangeNotifierProvider.value(value: _ffi.canvasModel),
],
child: getRawPointerAndKeyBody(
keyboard,
Scaffold(
// resizeToAvoidBottomInset: true,
floatingActionButton: !showActionButton
? null
: FloatingActionButton(
mini: !hideKeyboard,
child: Icon(hideKeyboard
? Icons.expand_more
: Icons.expand_less),
backgroundColor: MyTheme.accent,
onPressed: () {
setState(() {
if (hideKeyboard) {
_showEdit = false;
_ffi.invokeMethod(
"enable_soft_keyboard", false);
_mobileFocusNode.unfocus();
_physicalFocusNode.requestFocus();
} else {
_showBar = !_showBar;
}
});
}),
bottomNavigationBar: _showBar && hasDisplays
? getBottomAppBar(keyboard)
: null,
body: Overlay(
initialEntries: [
OverlayEntry(builder: (context) {
return Container(
color: Colors.black,
child: getBodyForDesktopWithListener(keyboard));
})
],
))),
));
child: getRawPointerAndKeyBody(Consumer<FfiModel>(
builder: (context, ffiModel, _child) => buildBody(ffiModel)))));
}
Widget getRawPointerAndKeyBody(bool keyboard, Widget child) {
Widget getRawPointerAndKeyBody(Widget child) {
return Listener(
onPointerHover: (e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
@ -352,8 +350,11 @@ class _RemotePageState extends State<RemotePage>
'{"id": "${widget.id}", "type": "wheel", "x": "$dx", "y": "$dy"}');
}
},
child: MouseRegion(
cursor: keyboard ? SystemMouseCursors.none : MouseCursor.defer,
child: Consumer<FfiModel>(
builder: (context, FfiModel, _child) => MouseRegion(
cursor: FfiModel.permissions['keyboard'] != false
? SystemMouseCursors.none
: MouseCursor.defer,
child: FocusScope(
autofocus: true,
child: Focus(
@ -397,10 +398,10 @@ class _RemotePageState extends State<RemotePage>
}
return KeyEventResult.handled;
},
child: child))));
child: child)))));
}
Widget getBottomAppBar(bool keyboard) {
Widget? getBottomAppBar() {
return BottomAppBar(
elevation: 10,
color: MyTheme.accent,
@ -515,6 +516,7 @@ class _RemotePageState extends State<RemotePage>
));
}
paints.add(getHelpTools());
return MouseRegion(
onEnter: (evt) {
bind.hostStopSystemKeyPropagate(stopped: false);