interactiveview not work on stack

This commit is contained in:
open-trade 2020-11-19 18:22:06 +08:00
parent 0eb19dcf2a
commit ad5eb7830c
3 changed files with 42 additions and 14 deletions

View File

@ -22,6 +22,7 @@ class _HomePageState extends State<HomePage> {
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<HomePage> {
getSearchBarUI(),
Expanded(child: Container())
]),
color: MyTheme.grayBg,
padding: const EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 0.0),
));
}

View File

@ -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();
}
}

View File

@ -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<RemotePage> {
// 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<RemotePage> {
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<RemotePage> {
)
: 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<ImageModel>(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<CursorModel>(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