From ad5eb7830c35f4aa6f6a4220ad3022ddd4fcfebc Mon Sep 17 00:00:00 2001 From: open-trade Date: Thu, 19 Nov 2020 18:22:06 +0800 Subject: [PATCH] interactiveview not work on stack --- flutter_hbb/lib/home_page.dart | 2 +- flutter_hbb/lib/model.dart | 7 +++-- flutter_hbb/lib/remote_page.dart | 47 +++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/flutter_hbb/lib/home_page.dart b/flutter_hbb/lib/home_page.dart index e22903611..40d05fe82 100644 --- a/flutter_hbb/lib/home_page.dart +++ b/flutter_hbb/lib/home_page.dart @@ -22,6 +22,7 @@ class _HomePageState extends State { if (_idController.text.isEmpty) _idController.text = FFI.getId(); // This method is rerun every time setState is called return Scaffold( + backgroundColor: MyTheme.grayBg, appBar: AppBar( title: Text(widget.title), ), @@ -34,7 +35,6 @@ class _HomePageState extends State { getSearchBarUI(), Expanded(child: Container()) ]), - color: MyTheme.grayBg, padding: const EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 0.0), )); } diff --git a/flutter_hbb/lib/model.dart b/flutter_hbb/lib/model.dart index 8ab833b78..594e73617 100644 --- a/flutter_hbb/lib/model.dart +++ b/flutter_hbb/lib/model.dart @@ -42,8 +42,9 @@ class FfiModel with ChangeNotifier { } void update(String id, BuildContext context) { - var evt = FFI.popEvent(); - if (evt != null) { + for (;;) { + var evt = FFI.popEvent(); + if (evt == null) break; var name = evt['name']; if (name == 'msgbox') { handleMsgbox(evt, id, context); @@ -139,7 +140,7 @@ class ImageModel with ChangeNotifier { void update(ui.Image image) { _image = image; - notifyListeners(); + if (image != null) notifyListeners(); } } diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index b844f0611..9180bb490 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'dart:ui' as ui; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'dart:async'; +import 'dart:math' as math; import 'common.dart'; import 'model.dart'; @@ -52,6 +53,7 @@ class _RemotePageState extends State { // Size size = MediaQueryData.fromWindow(ui.window).size; // MediaQuery.of(context).size.height; return Scaffold( + backgroundColor: MyTheme.grayBg, floatingActionButton: _show_bar ? null : FloatingActionButton( @@ -79,6 +81,13 @@ class _RemotePageState extends State { icon: Icon(Icons.keyboard), onPressed: () {}, ), + Transform.rotate( + angle: 15 * math.pi / 180, + child: IconButton( + color: Colors.white, + icon: Icon(Icons.flash_on), + onPressed: () {}, + )), IconButton( color: Colors.white, icon: Icon(Icons.tv), @@ -101,14 +110,18 @@ class _RemotePageState extends State { ) : null, body: FlutterEasyLoading( - child: InteractiveViewer( - constrained: false, - panEnabled: true, - onInteractionUpdate: (details) { - print("$details"); - }, - child: Container(child: ImagePaint(), color: MyTheme.grayBg), - ))); + child: InteractiveViewer( + constrained: false, + panEnabled: true, + onInteractionUpdate: (details) { + print("$details"); + }, + child: Stack(children: [ + ImagePaint(), + CursorPaint(), + ]), + ), + )); } } @@ -117,7 +130,17 @@ class ImagePaint extends StatelessWidget { Widget build(BuildContext context) { final m = Provider.of(context); return CustomPaint( - painter: new ImagePainter(image: m.image), + painter: new ImagePainter(image: m.image, x: 0, y: 0), + ); + } +} + +class CursorPaint extends StatelessWidget { + @override + Widget build(BuildContext context) { + final m = Provider.of(context); + return CustomPaint( + painter: new ImagePainter(image: m.image, x: m.x, y: m.y), ); } } @@ -125,14 +148,18 @@ class ImagePaint extends StatelessWidget { class ImagePainter extends CustomPainter { ImagePainter({ this.image, + this.x, + this.y, }); ui.Image image; + double x; + double y; @override void paint(Canvas canvas, Size size) { if (image == null) return; - canvas.drawImage(image, new Offset(0, 0), new Paint()); + canvas.drawImage(image, new Offset(x, y), new Paint()); } @override