add controls to gesture detector

This commit is contained in:
Nick Fisher
2021-11-24 11:47:56 +08:00
parent 7ae6d85878
commit 1fd75fb2b1

View File

@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'filament_controller.dart'; import 'filament_controller.dart';
@@ -5,10 +6,11 @@ import 'view/filament_widget.dart';
class GestureDetectingFilamentView extends StatefulWidget { class GestureDetectingFilamentView extends StatefulWidget {
final FilamentController controller; final FilamentController controller;
final bool rotate;
final bool showControls;
const GestureDetectingFilamentView( const GestureDetectingFilamentView(
{Key? key, required this.controller, this.rotate = false}) {Key? key, required this.controller, this.showControls = false})
: super(key: key); : super(key: key);
@override @override
@@ -17,32 +19,84 @@ class GestureDetectingFilamentView extends StatefulWidget {
class _GestureDetectingFilamentViewState class _GestureDetectingFilamentViewState
extends State<GestureDetectingFilamentView> { extends State<GestureDetectingFilamentView> {
int _primitiveIndex = 0; bool _rotate = false;
double _weight = 0.0;
@override
void didUpdateWidget(Widget oldWidget) {
if (widget.showControls !=
(oldWidget as GestureDetectingFilamentView).showControls) {
setState(() {});
}
super.didUpdateWidget(oldWidget);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return Stack(children: [
behavior: HitTestBehavior.opaque, Positioned.fill(
onPanDown: (details) { child: GestureDetector(
widget.rotate behavior: HitTestBehavior.opaque,
? widget.controller.rotateStart( onPanDown: (details) async {
details.localPosition.dx, details.localPosition.dy) await widget.controller.panEnd();
: widget.controller await widget.controller.rotateEnd();
.panStart(details.localPosition.dx, details.localPosition.dy); _rotate
}, ? widget.controller.rotateStart(
onPanUpdate: (details) { details.globalPosition.dx, details.globalPosition.dy)
widget.rotate : widget.controller.panStart(
? widget.controller.rotateUpdate( details.globalPosition.dx, details.globalPosition.dy);
details.localPosition.dx, details.localPosition.dy) },
: widget.controller.panUpdate( onPanUpdate: (details) {
details.localPosition.dx, details.localPosition.dy); _rotate
}, ? widget.controller.rotateUpdate(
onPanEnd: (d) { details.globalPosition.dx, details.globalPosition.dy)
widget.rotate : widget.controller.panUpdate(
? widget.controller.rotateEnd() details.globalPosition.dx, details.globalPosition.dy);
: widget.controller.panEnd(); },
}, onPanEnd: (d) {
child: FilamentWidget(controller: widget.controller)); _rotate
? widget.controller.rotateEnd()
: widget.controller.panEnd();
},
child: FilamentWidget(controller: widget.controller))),
widget.showControls
? Padding(
padding: const EdgeInsets.all(50),
child: Row(children: [
Checkbox(
value: _rotate,
onChanged: (v) {
setState(() {
_rotate = v == true;
});
}),
ElevatedButton(
onPressed: () => widget.controller.zoom(30.0),
child: const Text('-')),
ElevatedButton(
onPressed: () => widget.controller.zoom(-30.0),
child: const Text('+'))
]))
: Container()
]);
} }
} }
// behavior: HitTestBehavior.opaque,
// onPanDown: (details) {
// _rotate
// ? _filamentController.rotateStart(
// details.globalPosition.dx, details.globalPosition.dy)
// : _filamentController.panStart(
// details.globalPosition.dx, details.globalPosition.dy);
// },
// onPanUpdate: (details) {
// _rotate
// ? _filamentController.rotateUpdate(
// details.globalPosition.dx, details.globalPosition.dy)
// : _filamentController.panUpdate(
// details.globalPosition.dx, details.globalPosition.dy);
// },
// onPanEnd: (d) {
// _rotate
// ? _filamentController.rotateEnd()
// : _filamentController.panEnd();
// },