Refactor gesture type enum to use camelCase

This commit is contained in:
LukasPoque
2023-11-06 17:13:25 +01:00
parent 9862f39bcd
commit 793bc6ca32
2 changed files with 13 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ import 'package:flutter_filament/widgets/filament_gesture_detector_desktop.dart'
import 'package:flutter_filament/widgets/filament_gesture_detector_mobile.dart'; import 'package:flutter_filament/widgets/filament_gesture_detector_mobile.dart';
import '../filament_controller.dart'; import '../filament_controller.dart';
enum GestureType { RotateCamera, PanCamera, PanBackground } enum GestureType { rotateCamera, panCamera, panBackground }
/// ///
/// A widget that translates finger/mouse gestures to zoom/pan/rotate actions. /// A widget that translates finger/mouse gestures to zoom/pan/rotate actions.

View File

@@ -2,7 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../filament_controller.dart'; import '../filament_controller.dart';
enum GestureType { RotateCamera, PanCamera, PanBackground } enum GestureType { rotateCamera, panCamera, panBackground }
/// ///
/// A widget that translates finger/mouse gestures to zoom/pan/rotate actions. /// A widget that translates finger/mouse gestures to zoom/pan/rotate actions.
@@ -49,12 +49,12 @@ class FilamentGestureDetectorMobile extends StatefulWidget {
class _FilamentGestureDetectorMobileState class _FilamentGestureDetectorMobileState
extends State<FilamentGestureDetectorMobile> { extends State<FilamentGestureDetectorMobile> {
GestureType gestureType = GestureType.PanCamera; GestureType gestureType = GestureType.panCamera;
final _icons = { final _icons = {
GestureType.PanBackground: Icons.image, GestureType.panBackground: Icons.image,
GestureType.PanCamera: Icons.pan_tool, GestureType.panCamera: Icons.pan_tool,
GestureType.RotateCamera: Icons.rotate_90_degrees_ccw GestureType.rotateCamera: Icons.rotate_90_degrees_ccw
}; };
// on mobile, we can't differentiate between pointer down events like we do on desktop with primary/secondary/tertiary buttons // on mobile, we can't differentiate between pointer down events like we do on desktop with primary/secondary/tertiary buttons
@@ -69,8 +69,11 @@ class _FilamentGestureDetectorMobileState
// to avoid duplicating code for pan/rotate (panStart, panUpdate, panEnd, rotateStart, rotateUpdate etc) // to avoid duplicating code for pan/rotate (panStart, panUpdate, panEnd, rotateStart, rotateUpdate etc)
// we have only a single function for start/update/end. // we have only a single function for start/update/end.
// when the gesture type is changed, these properties are updated to point to the correct function. // when the gesture type is changed, these properties are updated to point to the correct function.
// ignore: unused_field
late Function(double x, double y) _functionStart; late Function(double x, double y) _functionStart;
// ignore: unused_field
late Function(double x, double y) _functionUpdate; late Function(double x, double y) _functionUpdate;
// ignore: unused_field
late Function() _functionEnd; late Function() _functionEnd;
@override @override
@@ -81,18 +84,18 @@ class _FilamentGestureDetectorMobileState
void _setFunction() { void _setFunction() {
switch (gestureType) { switch (gestureType) {
case GestureType.RotateCamera: case GestureType.rotateCamera:
_functionStart = widget.controller.rotateStart; _functionStart = widget.controller.rotateStart;
_functionUpdate = widget.controller.rotateUpdate; _functionUpdate = widget.controller.rotateUpdate;
_functionEnd = widget.controller.rotateEnd; _functionEnd = widget.controller.rotateEnd;
break; break;
case GestureType.PanCamera: case GestureType.panCamera:
_functionStart = widget.controller.panStart; _functionStart = widget.controller.panStart;
_functionUpdate = widget.controller.panUpdate; _functionUpdate = widget.controller.panUpdate;
_functionEnd = widget.controller.panEnd; _functionEnd = widget.controller.panEnd;
break; break;
// TODO // TODO
case GestureType.PanBackground: case GestureType.panBackground:
_functionStart = (x, y) async {}; _functionStart = (x, y) async {};
_functionUpdate = (x, y) async {}; _functionUpdate = (x, y) async {};
_functionEnd = () async {}; _functionEnd = () async {};
@@ -109,6 +112,7 @@ class _FilamentGestureDetectorMobileState
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
} }
// ignore: unused_field
Timer? _scrollTimer; Timer? _scrollTimer;
double _lastScale = 0; double _lastScale = 0;