77 lines
1.8 KiB
Dart
77 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
void main() {
|
|
runApp(
|
|
MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
home: SomaticCursorPage()),
|
|
);
|
|
}
|
|
|
|
class SomaticCursorPage extends StatefulWidget {
|
|
@override
|
|
_SomaticCursorPageState createState() => _SomaticCursorPageState();
|
|
}
|
|
|
|
class _SomaticCursorPageState extends State<SomaticCursorPage> {
|
|
static const _eventChannel = EventChannel("sensor");
|
|
|
|
double x = 0;
|
|
double y = 0;
|
|
double offsetX = 0;
|
|
double offsetY = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_eventChannel.receiveBroadcastStream().listen((data) {
|
|
if (data is List) {
|
|
setState(() {
|
|
x = (data[0] * 20 * 100) - offsetX;
|
|
y = (data[1] * 30 * 100) - offsetY;
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
body: Stack(
|
|
children: [
|
|
Center(
|
|
child: Transform.translate(
|
|
offset: Offset(x, y),
|
|
child: Container(
|
|
width: 50,
|
|
height: 50,
|
|
decoration: BoxDecoration(
|
|
color: Colors.blue,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(40.0),
|
|
child: IconButton(
|
|
icon: Icon(Icons.refresh, size: 40),
|
|
onPressed: () {
|
|
setState(() {
|
|
offsetX += x;
|
|
offsetY += y;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|