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(); if (_idController.text.isEmpty) _idController.text = FFI.getId();
// This method is rerun every time setState is called // This method is rerun every time setState is called
return Scaffold( return Scaffold(
backgroundColor: MyTheme.grayBg,
appBar: AppBar( appBar: AppBar(
title: Text(widget.title), title: Text(widget.title),
), ),
@ -34,7 +35,6 @@ class _HomePageState extends State<HomePage> {
getSearchBarUI(), getSearchBarUI(),
Expanded(child: Container()) Expanded(child: Container())
]), ]),
color: MyTheme.grayBg,
padding: const EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 0.0), 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) { void update(String id, BuildContext context) {
var evt = FFI.popEvent(); for (;;) {
if (evt != null) { var evt = FFI.popEvent();
if (evt == null) break;
var name = evt['name']; var name = evt['name'];
if (name == 'msgbox') { if (name == 'msgbox') {
handleMsgbox(evt, id, context); handleMsgbox(evt, id, context);
@ -139,7 +140,7 @@ class ImageModel with ChangeNotifier {
void update(ui.Image image) { void update(ui.Image image) {
_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 'dart:ui' as ui;
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'dart:async'; import 'dart:async';
import 'dart:math' as math;
import 'common.dart'; import 'common.dart';
import 'model.dart'; import 'model.dart';
@ -52,6 +53,7 @@ class _RemotePageState extends State<RemotePage> {
// Size size = MediaQueryData.fromWindow(ui.window).size; // Size size = MediaQueryData.fromWindow(ui.window).size;
// MediaQuery.of(context).size.height; // MediaQuery.of(context).size.height;
return Scaffold( return Scaffold(
backgroundColor: MyTheme.grayBg,
floatingActionButton: _show_bar floatingActionButton: _show_bar
? null ? null
: FloatingActionButton( : FloatingActionButton(
@ -79,6 +81,13 @@ class _RemotePageState extends State<RemotePage> {
icon: Icon(Icons.keyboard), icon: Icon(Icons.keyboard),
onPressed: () {}, onPressed: () {},
), ),
Transform.rotate(
angle: 15 * math.pi / 180,
child: IconButton(
color: Colors.white,
icon: Icon(Icons.flash_on),
onPressed: () {},
)),
IconButton( IconButton(
color: Colors.white, color: Colors.white,
icon: Icon(Icons.tv), icon: Icon(Icons.tv),
@ -101,14 +110,18 @@ class _RemotePageState extends State<RemotePage> {
) )
: null, : null,
body: FlutterEasyLoading( body: FlutterEasyLoading(
child: InteractiveViewer( child: InteractiveViewer(
constrained: false, constrained: false,
panEnabled: true, panEnabled: true,
onInteractionUpdate: (details) { onInteractionUpdate: (details) {
print("$details"); print("$details");
}, },
child: Container(child: ImagePaint(), color: MyTheme.grayBg), child: Stack(children: [
))); ImagePaint(),
CursorPaint(),
]),
),
));
} }
} }
@ -117,7 +130,17 @@ class ImagePaint extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final m = Provider.of<ImageModel>(context); final m = Provider.of<ImageModel>(context);
return CustomPaint( 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 { class ImagePainter extends CustomPainter {
ImagePainter({ ImagePainter({
this.image, this.image,
this.x,
this.y,
}); });
ui.Image image; ui.Image image;
double x;
double y;
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
if (image == null) return; if (image == null) return;
canvas.drawImage(image, new Offset(0, 0), new Paint()); canvas.drawImage(image, new Offset(x, y), new Paint());
} }
@override @override