From ed434fa90ef64fb07c1678abca31fb7314f147c0 Mon Sep 17 00:00:00 2001 From: Kingtous Date: Fri, 17 Jun 2022 00:06:49 +0800 Subject: [PATCH] add: use multi provider for canvas Signed-off-by: Kingtous --- flutter/lib/desktop/pages/remote_page.dart | 118 +++++++++++---------- 1 file changed, 63 insertions(+), 55 deletions(-) diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index 5930b1f5a..30e647593 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -241,52 +241,61 @@ class _RemotePageState extends State with WindowListener { return WillPopScope( onWillPop: () async { - clientClose(); - return false; - }, - 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 && pi.displays.length > 0 - ? getBottomAppBar(keyboard) - : null, - body: Overlay( - initialEntries: [ - OverlayEntry(builder: (context) { - return Container( - color: Colors.black, - child: isWebDesktop - ? getBodyForDesktopWithListener(keyboard) - : SafeArea( - child: Container( - color: MyTheme.canvasColor, - child: _isPhysicalMouse - ? getBodyForMobile() - : getBodyForMobileWithGesture()))); - }) - ], - ))), - ); + clientClose(); + return false; + }, + child: MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: _ffi.ffiModel), + ChangeNotifierProvider.value(value: _ffi.imageModel), + 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 && pi.displays.length > 0 + ? getBottomAppBar(keyboard) + : null, + body: Overlay( + initialEntries: [ + OverlayEntry(builder: (context) { + 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) { @@ -916,13 +925,12 @@ class ImagePaint extends StatelessWidget { @override Widget build(BuildContext context) { - final m = ffi(this.id).imageModel; - final c = ffi(this.id).canvasModel; - final adjust = ffi(this.id).cursorModel.adjustForKeyboard(); + final m = Provider.of(context); + final c = Provider.of(context); var s = c.scale; return CustomPaint( - painter: new ImagePainter( - image: m.image, x: c.x / s, y: (c.y - adjust) / s, scale: s), + painter: + new ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s), ); } } @@ -934,15 +942,15 @@ class CursorPaint extends StatelessWidget { @override Widget build(BuildContext context) { - final m = ffi(this.id).cursorModel; - final c = ffi(this.id).canvasModel; - final adjust = ffi(this.id).cursorModel.adjustForKeyboard(); + final m = Provider.of(context); + final c = Provider.of(context); + // final adjust = m.adjustForKeyboard(); var s = c.scale; return CustomPaint( painter: new ImagePainter( image: m.image, 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), ); }