Refactor: Ajustement des valeurs limites de taille (0.5 à 1.1) pour synchroniser le slider et le geste tactile
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
/// Les anneaux sont répartis proportionnellement.
|
/// Les anneaux sont répartis proportionnellement.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
|
import 'dart:math' as math;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../../core/theme/app_theme.dart';
|
import '../../../core/theme/app_theme.dart';
|
||||||
import '../../../data/models/target_type.dart';
|
import '../../../data/models/target_type.dart';
|
||||||
@@ -57,6 +58,9 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
|||||||
// Contrôle de l'affichage du scroll d'espacement (désactivé par défaut)
|
// Contrôle de l'affichage du scroll d'espacement (désactivé par défaut)
|
||||||
bool _showEspacement = false;
|
bool _showEspacement = false;
|
||||||
|
|
||||||
|
// Variable temporaire pour stocker la valeur du rayon au début du pincement tactile
|
||||||
|
double _baseRadiusBeforeScale = 1.0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -125,10 +129,22 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
|||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
|
// Utilisation d'un Gesture Detector basé sur le Scale pour synchroniser à 1 ou 2 doigts
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onPanStart: (details) => _onPanStart(details, size),
|
onScaleStart: (details) {
|
||||||
onPanUpdate: (details) => _onPanUpdate(details, size),
|
_baseRadiusBeforeScale = _radius;
|
||||||
onPanEnd: (_) => _onPanEnd(),
|
final tapX = details.localFocalPoint.dx / size.width;
|
||||||
|
final tapY = details.localFocalPoint.dy / size.height;
|
||||||
|
final distToCenter = _distance(tapX, tapY, _centerX, _centerY);
|
||||||
|
|
||||||
|
if (distToCenter < 0.05 || distToCenter < _radius + 0.02) {
|
||||||
|
setState(() {
|
||||||
|
_isDraggingCenter = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onScaleUpdate: (details) => _onScaleUpdate(details, size),
|
||||||
|
onScaleEnd: (_) => _onScaleEnd(),
|
||||||
child: CustomPaint(
|
child: CustomPaint(
|
||||||
size: size,
|
size: size,
|
||||||
painter: _CalibrationPainter(
|
painter: _CalibrationPainter(
|
||||||
@@ -156,7 +172,7 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
|||||||
children: [
|
children: [
|
||||||
// Ligne d'activation pour afficher ou masquer l'espacement
|
// Ligne d'activation pour afficher ou masquer l'espacement
|
||||||
Container(
|
Container(
|
||||||
margin: const EdgeInsets.only(bottom: 8), // CORRECTION de la syntaxe de marge
|
margin: const EdgeInsets.only(bottom: 8),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.black54,
|
color: Colors.black54,
|
||||||
@@ -173,7 +189,7 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
|||||||
height: 28,
|
height: 28,
|
||||||
child: Switch(
|
child: Switch(
|
||||||
value: _showEspacement,
|
value: _showEspacement,
|
||||||
activeThumbColor: const Color(0xFF00FF00), // CORRECTION du paramètre déprécié
|
activeThumbColor: const Color(0xFF00FF00),
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_showEspacement = value;
|
_showEspacement = value;
|
||||||
@@ -198,9 +214,9 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
|||||||
const Icon(Icons.zoom_out, color: Colors.white, size: 16),
|
const Icon(Icons.zoom_out, color: Colors.white, size: 16),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Slider(
|
child: Slider(
|
||||||
value: _radius.clamp(0.3, 1.2),
|
value: _radius.clamp(0.5, 1.1),
|
||||||
min: 0.3,
|
min: 0.5,
|
||||||
max: 1.2,
|
max: 1.1,
|
||||||
activeColor: AppTheme.primaryColor,
|
activeColor: AppTheme.primaryColor,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -332,25 +348,17 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
|||||||
_notifyChange();
|
_notifyChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onPanStart(DragStartDetails details, Size size) {
|
// Traitement intelligent des gestes tactiles
|
||||||
final tapX = details.localPosition.dx / size.width;
|
void _onScaleUpdate(ScaleUpdateDetails details, Size size) {
|
||||||
final tapY = details.localPosition.dy / size.height;
|
|
||||||
|
|
||||||
final distToCenter = _distance(tapX, tapY, _centerX, _centerY);
|
|
||||||
|
|
||||||
if (distToCenter < 0.05 || distToCenter < _radius + 0.02) {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isDraggingCenter = true;
|
if (details.pointerCount == 2) {
|
||||||
});
|
// GESTE À DEUX DOIGTS : On calcule le zoom en respectant le range strict (0.3 à 1.2)
|
||||||
}
|
_radius = (_baseRadiusBeforeScale * details.scale).clamp(0.5, 1.1);
|
||||||
}
|
_initRingRadii(forceRecalculate: true);
|
||||||
|
} else if (_isDraggingCenter) {
|
||||||
void _onPanUpdate(DragUpdateDetails details, Size size) {
|
// GESTE À UN SEUL DOIGT : Déplacement fluide du centre de la cible
|
||||||
final deltaX = details.delta.dx / size.width;
|
final deltaX = details.focalPointDelta.dx / size.width;
|
||||||
final deltaY = details.delta.dy / size.height;
|
final deltaY = details.focalPointDelta.dy / size.height;
|
||||||
|
|
||||||
setState(() {
|
|
||||||
if (_isDraggingCenter) {
|
|
||||||
_centerX = _centerX + deltaX;
|
_centerX = _centerX + deltaX;
|
||||||
_centerY = _centerY + deltaY;
|
_centerY = _centerY + deltaY;
|
||||||
}
|
}
|
||||||
@@ -359,7 +367,7 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
|||||||
_notifyChange();
|
_notifyChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onPanEnd() {
|
void _onScaleEnd() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isDraggingCenter = false;
|
_isDraggingCenter = false;
|
||||||
_isDraggingRadius = false;
|
_isDraggingRadius = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user