Merge pull request #794 from Kingtous/flutter_desktop

fix: use multi provider for canvas
This commit is contained in:
RustDesk 2022-06-17 00:13:07 +08:00 committed by GitHub
commit 593bdda990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -241,52 +241,61 @@ class _RemotePageState extends State<RemotePage> with WindowListener {
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
clientClose(); clientClose();
return false; return false;
}, },
child: getRawPointerAndKeyBody( child: MultiProvider(
keyboard, providers: [
Scaffold( ChangeNotifierProvider.value(value: _ffi.ffiModel),
// resizeToAvoidBottomInset: true, ChangeNotifierProvider.value(value: _ffi.imageModel),
floatingActionButton: !showActionButton ChangeNotifierProvider.value(value: _ffi.cursorModel),
? null ChangeNotifierProvider.value(value: _ffi.canvasModel),
: FloatingActionButton( ],
mini: !hideKeyboard, child: getRawPointerAndKeyBody(
child: Icon( keyboard,
hideKeyboard ? Icons.expand_more : Icons.expand_less), Scaffold(
backgroundColor: MyTheme.accent, // resizeToAvoidBottomInset: true,
onPressed: () { floatingActionButton: !showActionButton
setState(() { ? null
if (hideKeyboard) { : FloatingActionButton(
_showEdit = false; mini: !hideKeyboard,
_ffi.invokeMethod("enable_soft_keyboard", false); child: Icon(hideKeyboard
_mobileFocusNode.unfocus(); ? Icons.expand_more
_physicalFocusNode.requestFocus(); : Icons.expand_less),
} else { backgroundColor: MyTheme.accent,
_showBar = !_showBar; onPressed: () {
} setState(() {
}); if (hideKeyboard) {
}), _showEdit = false;
bottomNavigationBar: _showBar && pi.displays.length > 0 _ffi.invokeMethod(
? getBottomAppBar(keyboard) "enable_soft_keyboard", false);
: null, _mobileFocusNode.unfocus();
body: Overlay( _physicalFocusNode.requestFocus();
initialEntries: [ } else {
OverlayEntry(builder: (context) { _showBar = !_showBar;
return Container( }
color: Colors.black, });
child: isWebDesktop }),
? getBodyForDesktopWithListener(keyboard) bottomNavigationBar: _showBar && pi.displays.length > 0
: SafeArea( ? getBottomAppBar(keyboard)
child: Container( : null,
color: MyTheme.canvasColor, body: Overlay(
child: _isPhysicalMouse initialEntries: [
? getBodyForMobile() OverlayEntry(builder: (context) {
: getBodyForMobileWithGesture()))); return Container(
}) color: Colors.black,
], child: isWebDesktop
))), ? getBodyForDesktopWithListener(keyboard)
); : SafeArea(
child: Container(
color: MyTheme.canvasColor,
child: _isPhysicalMouse
? getBodyForMobile()
: getBodyForMobileWithGesture())));
})
],
))),
));
} }
Widget getRawPointerAndKeyBody(bool keyboard, Widget child) { Widget getRawPointerAndKeyBody(bool keyboard, Widget child) {
@ -916,13 +925,12 @@ class ImagePaint extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final m = ffi(this.id).imageModel; final m = Provider.of<ImageModel>(context);
final c = ffi(this.id).canvasModel; final c = Provider.of<CanvasModel>(context);
final adjust = ffi(this.id).cursorModel.adjustForKeyboard();
var s = c.scale; var s = c.scale;
return CustomPaint( return CustomPaint(
painter: new ImagePainter( painter:
image: m.image, x: c.x / s, y: (c.y - adjust) / s, scale: s), new ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s),
); );
} }
} }
@ -934,15 +942,15 @@ class CursorPaint extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final m = ffi(this.id).cursorModel; final m = Provider.of<CursorModel>(context);
final c = ffi(this.id).canvasModel; final c = Provider.of<CanvasModel>(context);
final adjust = ffi(this.id).cursorModel.adjustForKeyboard(); // final adjust = m.adjustForKeyboard();
var s = c.scale; var s = c.scale;
return CustomPaint( return CustomPaint(
painter: new ImagePainter( painter: new ImagePainter(
image: m.image, image: m.image,
x: m.x * s - m.hotx + c.x, x: m.x * s - m.hotx + c.x,
y: m.y * s - m.hoty + c.y - adjust, y: m.y * s - m.hoty + c.y,
scale: 1), scale: 1),
); );
} }