2020-11-17 01:22:14 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2020-11-18 23:15:59 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2020-11-17 01:22:14 +08:00
|
|
|
import 'package:flutter/services.dart';
|
2020-11-17 11:12:55 +08:00
|
|
|
import 'dart:ui' as ui;
|
2020-11-17 12:08:31 +08:00
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
import 'dart:async';
|
2020-11-19 18:22:06 +08:00
|
|
|
import 'dart:math' as math;
|
2020-11-19 00:32:46 +08:00
|
|
|
import 'common.dart';
|
|
|
|
import 'model.dart';
|
2020-11-19 21:59:49 +08:00
|
|
|
import 'package:tuple/tuple.dart';
|
2020-11-17 01:22:14 +08:00
|
|
|
|
|
|
|
class RemotePage extends StatefulWidget {
|
|
|
|
RemotePage({Key key, this.id}) : super(key: key);
|
|
|
|
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
@override
|
|
|
|
_RemotePageState createState() => _RemotePageState();
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:08:31 +08:00
|
|
|
// https://github.com/hanxu317317/flutter_plan_demo/blob/master/lib/src/enter.dart
|
2020-11-17 01:22:14 +08:00
|
|
|
class _RemotePageState extends State<RemotePage> {
|
2020-11-17 12:08:31 +08:00
|
|
|
Timer _interval;
|
2020-11-20 00:29:59 +08:00
|
|
|
bool _showBar = true;
|
2020-11-17 12:08:31 +08:00
|
|
|
|
2020-11-17 11:12:55 +08:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
FFI.connect(widget.id);
|
2020-11-17 12:08:31 +08:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2020-11-18 18:20:13 +08:00
|
|
|
// https://stackoverflow.com/questions/46640116/make-flutter-application-fullscreen
|
|
|
|
SystemChrome.setEnabledSystemUIOverlays([]);
|
2020-11-18 00:28:55 +08:00
|
|
|
showLoading('Connecting...');
|
2020-11-17 12:08:31 +08:00
|
|
|
_interval =
|
|
|
|
Timer.periodic(Duration(milliseconds: 30), (timer) => interval());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
2020-11-17 12:41:23 +08:00
|
|
|
FFI.close();
|
2020-11-17 12:08:31 +08:00
|
|
|
_interval.cancel();
|
|
|
|
dismissLoading();
|
2020-11-18 18:20:13 +08:00
|
|
|
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
|
2020-11-17 12:08:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void interval() {
|
2020-11-19 21:59:49 +08:00
|
|
|
FFI.ffiModel.update(widget.id, context, handleMsgbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleMsgbox(Map<String, dynamic> evt, String id, BuildContext context) {
|
|
|
|
var type = evt['type'];
|
|
|
|
var title = evt['title'];
|
|
|
|
var text = evt['text'];
|
|
|
|
if (type == 're-input-password') {
|
|
|
|
wrongPasswordDialog(id, context);
|
|
|
|
} else if (type == 'input-password') {
|
|
|
|
enterPasswordDialog(id, context);
|
|
|
|
} else {
|
|
|
|
msgbox(type, title, text, context);
|
|
|
|
}
|
2020-11-17 11:12:55 +08:00
|
|
|
}
|
2020-11-17 01:22:14 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-11-17 12:08:31 +08:00
|
|
|
// Size size = MediaQueryData.fromWindow(ui.window).size;
|
2020-11-17 12:41:23 +08:00
|
|
|
// MediaQuery.of(context).size.height;
|
2020-11-19 18:41:37 +08:00
|
|
|
EasyLoading.instance.loadingStyle = EasyLoadingStyle.light;
|
2020-11-19 17:22:42 +08:00
|
|
|
return Scaffold(
|
2020-11-20 00:29:59 +08:00
|
|
|
floatingActionButton: _showBar
|
2020-11-19 17:22:42 +08:00
|
|
|
? null
|
|
|
|
: FloatingActionButton(
|
|
|
|
mini: true,
|
|
|
|
child: Icon(Icons.expand_less),
|
|
|
|
backgroundColor: MyTheme.accent50,
|
|
|
|
onPressed: () {
|
2020-11-20 00:29:59 +08:00
|
|
|
setState(() => _showBar = !_showBar);
|
2020-11-19 17:22:42 +08:00
|
|
|
}),
|
2020-11-20 00:29:59 +08:00
|
|
|
bottomNavigationBar: _showBar
|
2020-11-19 17:22:42 +08:00
|
|
|
? BottomAppBar(
|
|
|
|
color: MyTheme.accent,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(children: [
|
|
|
|
IconButton(
|
|
|
|
color: Colors.white,
|
|
|
|
icon: Icon(Icons.clear),
|
|
|
|
onPressed: () {},
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
color: Colors.white,
|
|
|
|
icon: Icon(Icons.keyboard),
|
|
|
|
onPressed: () {},
|
|
|
|
),
|
2020-11-19 18:22:06 +08:00
|
|
|
Transform.rotate(
|
|
|
|
angle: 15 * math.pi / 180,
|
|
|
|
child: IconButton(
|
|
|
|
color: Colors.white,
|
|
|
|
icon: Icon(Icons.flash_on),
|
|
|
|
onPressed: () {},
|
|
|
|
)),
|
2020-11-19 17:22:42 +08:00
|
|
|
IconButton(
|
|
|
|
color: Colors.white,
|
|
|
|
icon: Icon(Icons.tv),
|
|
|
|
onPressed: () {},
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
color: Colors.white,
|
|
|
|
icon: Icon(Icons.settings),
|
|
|
|
onPressed: () {},
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
IconButton(
|
|
|
|
color: Colors.white,
|
|
|
|
icon: Icon(Icons.expand_more),
|
|
|
|
onPressed: () {
|
2020-11-20 00:29:59 +08:00
|
|
|
setState(() => _showBar = !_showBar);
|
2020-11-19 17:22:42 +08:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
body: FlutterEasyLoading(
|
2020-11-19 18:41:37 +08:00
|
|
|
child: Container(
|
|
|
|
color: MyTheme.canvasColor,
|
2020-11-19 18:22:06 +08:00
|
|
|
child: InteractiveViewer(
|
|
|
|
constrained: false,
|
|
|
|
panEnabled: true,
|
|
|
|
onInteractionUpdate: (details) {
|
|
|
|
print("$details");
|
|
|
|
},
|
|
|
|
child: Stack(children: [
|
|
|
|
ImagePaint(),
|
|
|
|
CursorPaint(),
|
|
|
|
]),
|
|
|
|
),
|
2020-11-19 18:41:37 +08:00
|
|
|
)));
|
2020-11-17 11:12:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-18 23:15:59 +08:00
|
|
|
class ImagePaint extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final m = Provider.of<ImageModel>(context);
|
|
|
|
return CustomPaint(
|
2020-11-19 18:22:06 +08:00
|
|
|
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),
|
2020-11-18 23:15:59 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ImagePainter extends CustomPainter {
|
|
|
|
ImagePainter({
|
2020-11-17 11:12:55 +08:00
|
|
|
this.image,
|
2020-11-19 18:22:06 +08:00
|
|
|
this.x,
|
|
|
|
this.y,
|
2020-11-17 11:12:55 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
ui.Image image;
|
2020-11-19 18:22:06 +08:00
|
|
|
double x;
|
|
|
|
double y;
|
2020-11-17 11:12:55 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
void paint(Canvas canvas, Size size) {
|
2020-11-17 12:08:31 +08:00
|
|
|
if (image == null) return;
|
2020-11-19 18:22:06 +08:00
|
|
|
canvas.drawImage(image, new Offset(x, y), new Paint());
|
2020-11-17 11:12:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool shouldRepaint(CustomPainter oldDelegate) {
|
2020-11-17 12:08:31 +08:00
|
|
|
return oldDelegate != this;
|
2020-11-17 01:22:14 +08:00
|
|
|
}
|
|
|
|
}
|
2020-11-19 21:59:49 +08:00
|
|
|
|
|
|
|
void enterPasswordDialog(String id, BuildContext context) {
|
|
|
|
final controller = TextEditingController();
|
|
|
|
var remember = FFI.getByName('remember', arg: id) == 'true';
|
|
|
|
showAlertDialog(
|
|
|
|
context,
|
|
|
|
(setState) => Tuple3(
|
|
|
|
Text('Please enter your password'),
|
|
|
|
Column(mainAxisSize: MainAxisSize.min, children: [
|
|
|
|
TextField(
|
|
|
|
autofocus: true,
|
|
|
|
obscureText: true,
|
|
|
|
controller: controller,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
labelText: 'Password',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'Remember the password',
|
|
|
|
),
|
|
|
|
leading: Checkbox(
|
|
|
|
value: remember,
|
|
|
|
onChanged: (v) {
|
|
|
|
setState(() {
|
|
|
|
remember = v;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
[
|
|
|
|
TextField(
|
|
|
|
autofocus: true,
|
|
|
|
obscureText: true,
|
|
|
|
controller: controller,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
labelText: 'Password',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'Remember the password',
|
|
|
|
),
|
|
|
|
leading: Checkbox(
|
|
|
|
value: remember,
|
|
|
|
onChanged: (v) {
|
|
|
|
setState(() {
|
|
|
|
remember = v;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
void wrongPasswordDialog(String id, BuildContext context) {
|
|
|
|
showAlertDialog(
|
|
|
|
context,
|
|
|
|
(_) =>
|
|
|
|
Tuple3(Text('Wrong Password'), Text('Do you want to enter again?'), [
|
|
|
|
FlatButton(
|
|
|
|
textColor: MyTheme.accent,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
child: Text('Cancel'),
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
textColor: MyTheme.accent,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
enterPasswordDialog(id, context);
|
|
|
|
},
|
|
|
|
child: Text('Retry'),
|
|
|
|
),
|
|
|
|
]));
|
|
|
|
}
|