Restore UI functionalities and clean up dependencies

This commit is contained in:
streaper2
2026-05-08 08:32:58 +02:00
parent 8946955f76
commit 0895b7d5bc
26751 changed files with 4207476 additions and 158 deletions

View File

@@ -1,124 +1,286 @@
import 'dart:io';
import 'package:flutter/material.dart';
// Importations ajustées selon ton arborescence à gauche
import '../../data/models/target_type.dart';
import '../analysis/analysis_screen.dart';
class CropScreen extends StatefulWidget {
final String imagePath;
final TargetType targetType;
const CropScreen({
super.key,
required this.imagePath,
required this.targetType,
});
@override
State<CropScreen> createState() => _CropScreenState();
}
class _CropScreenState extends State<CropScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF101214),
appBar: AppBar(
backgroundColor: const Color(0xFF101214),
elevation: 0,
centerTitle: true,
title: const Text(
'Validation image',
style: TextStyle(color: Colors.white, fontSize: 18),
),
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
),
body: Column(
children: [
// L'image capturée
Expanded(
child: Container(
margin: const EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.white10),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image.file(
File(widget.imagePath),
fit: BoxFit.contain,
),
),
),
),
// Bouton Modifier
Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: ElevatedButton.icon(
onPressed: () {
// Logique de modification à venir
},
icon: const Icon(Icons.crop_rotate),
label: const Text('Modifier'),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF1A73E8),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
),
),
// Boutons du bas
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 30),
child: Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
side: const BorderSide(color: Colors.white24),
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('Recommencer', style: TextStyle(color: Colors.white)),
),
),
const SizedBox(width: 16),
Expanded(
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => AnalysisScreen(
imagePath: widget.imagePath,
targetType: widget.targetType,
),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF1A73E8),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('Valider', style: TextStyle(fontWeight: FontWeight.bold)),
),
),
],
),
),
],
),
);
}
}
import 'dart:io';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import '../../core/theme/app_theme.dart';
import '../../data/models/target_type.dart';
import '../../services/image_crop_service.dart';
import '../analysis/analysis_screen.dart';
import 'widgets/crop_overlay.dart';
class CropScreen extends StatefulWidget {
final String imagePath;
final TargetType targetType;
const CropScreen({
super.key,
required this.imagePath,
required this.targetType,
});
@override
State<CropScreen> createState() => _CropScreenState();
}
class _CropScreenState extends State<CropScreen> {
final ImageCropService _cropService = ImageCropService();
// États de transformation
double _scale = 1.0;
double _baseScale = 1.0;
Offset _offset = Offset.zero;
Offset _startOffset = Offset.zero;
Offset _startFocalPoint = Offset.zero;
bool _isLoading = false;
bool _imageLoaded = false;
Size? _imageSize;
late Size _viewportSize;
late double _cropSize;
@override
void initState() {
super.initState();
_loadImageInfo();
}
Future<void> _loadImageInfo() async {
final file = File(widget.imagePath);
final decodedImage = await decodeImageFromList(await file.readAsBytes());
if (mounted) {
setState(() {
_imageSize = Size(
decodedImage.width.toDouble(),
decodedImage.height.toDouble(),
);
_imageLoaded = true;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF101214),
appBar: AppBar(
backgroundColor: const Color(0xFF101214),
elevation: 0,
centerTitle: true,
title: const Text(
'Validation image',
style: TextStyle(color: Colors.white, fontSize: 18),
),
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
),
body: _isLoading
? const Center(child: CircularProgressIndicator(color: Color(0xFF1A73E8)))
: Column(
children: [
// Zone interactive de crop
Expanded(
child: Container(
margin: const EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.white10),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: _imageLoaded ? _buildInteractiveCrop() : const Center(child: CircularProgressIndicator()),
),
),
),
// Bouton d'aide / Modifier
Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.touch_app, color: Colors.white54, size: 20),
const SizedBox(width: 8),
Text(
'Déplacez et zoomez pour cadrer',
style: TextStyle(color: Colors.white.withOpacity(0.6), fontSize: 14),
),
],
),
),
// Boutons du bas
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 30),
child: Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
side: const BorderSide(color: Colors.white24),
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('Recommencer', style: TextStyle(color: Colors.white)),
),
),
const SizedBox(width: 16),
Expanded(
child: ElevatedButton(
onPressed: _onCropConfirm,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF1A73E8),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('Valider', style: TextStyle(fontWeight: FontWeight.bold)),
),
),
],
),
),
],
),
);
}
Widget _buildInteractiveCrop() {
return LayoutBuilder(
builder: (context, constraints) {
_viewportSize = Size(constraints.maxWidth, constraints.maxHeight);
_cropSize = math.min(constraints.maxWidth, constraints.maxHeight) * 0.9;
if (_scale == 1.0 && _offset == Offset.zero) {
_initializeImagePosition();
}
return GestureDetector(
onScaleStart: _onScaleStart,
onScaleUpdate: _onScaleUpdate,
child: Stack(
children: [
Positioned.fill(
child: Center(
child: Transform(
transform: Matrix4.identity()
..setTranslationRaw(_offset.dx, _offset.dy, 0)
..scale(_scale, _scale),
alignment: Alignment.center,
child: Image.file(
File(widget.imagePath),
fit: BoxFit.contain,
width: _viewportSize.width,
height: _viewportSize.height,
),
),
),
),
Positioned.fill(
child: IgnorePointer(
child: CropOverlay(cropSize: _cropSize, showGrid: true),
),
),
],
),
);
},
);
}
void _initializeImagePosition() {
if (_imageSize == null) return;
final imageAspect = _imageSize!.width / _imageSize!.height;
final viewportAspect = _viewportSize.width / _viewportSize.height;
double displayWidth, displayHeight;
if (imageAspect > viewportAspect) {
displayWidth = _viewportSize.width;
displayHeight = _viewportSize.width / imageAspect;
} else {
displayHeight = _viewportSize.height;
displayWidth = _viewportSize.height * imageAspect;
}
final minDisplayDim = math.min(displayWidth, displayHeight);
_scale = _cropSize / minDisplayDim;
if (_scale < 1.0) _scale = 1.0;
}
void _onScaleStart(ScaleStartDetails details) {
_baseScale = _scale;
_startFocalPoint = details.focalPoint;
_startOffset = _offset;
}
void _onScaleUpdate(ScaleUpdateDetails details) {
setState(() {
_scale = (_baseScale * details.scale).clamp(0.5, 5.0);
final delta = details.focalPoint - _startFocalPoint;
_offset = _startOffset + delta;
});
}
Future<void> _onCropConfirm() async {
setState(() => _isLoading = true);
try {
final cropRect = _calculateCropRect();
final croppedPath = await _cropService.cropToSquare(widget.imagePath, cropRect);
if (!mounted) return;
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => AnalysisScreen(
imagePath: croppedPath,
targetType: widget.targetType,
),
),
);
} catch (e) {
if (mounted) {
setState(() => _isLoading = false);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Erreur: $e'), backgroundColor: AppTheme.errorColor),
);
}
}
}
CropRect _calculateCropRect() {
if (_imageSize == null) return const CropRect(x: 0, y: 0, width: 1, height: 1);
final imageAspect = _imageSize!.width / _imageSize!.height;
final viewportAspect = _viewportSize.width / _viewportSize.height;
double displayWidth, displayHeight;
if (imageAspect > viewportAspect) {
displayWidth = _viewportSize.width;
displayHeight = _viewportSize.width / imageAspect;
} else {
displayHeight = _viewportSize.height;
displayWidth = _viewportSize.height * imageAspect;
}
final scaledWidth = displayWidth * _scale;
final scaledHeight = displayHeight * _scale;
final imageCenterX = _viewportSize.width / 2 + _offset.dx;
final imageCenterY = _viewportSize.height / 2 + _offset.dy;
final imageLeft = imageCenterX - scaledWidth / 2;
final imageTop = imageCenterY - scaledHeight / 2;
final cropLeft = (_viewportSize.width - _cropSize) / 2;
final cropTop = (_viewportSize.height - _cropSize) / 2;
final relCropLeft = (cropLeft - imageLeft) / scaledWidth;
final relCropTop = (cropTop - imageTop) / scaledHeight;
final relCropSize = _cropSize / scaledWidth;
final relCropSizeY = _cropSize / scaledHeight;
return CropRect(
x: relCropLeft.clamp(0.0, 1.0),
y: relCropTop.clamp(0.0, 1.0),
width: relCropSize.clamp(0.0, 1.0 - relCropLeft.clamp(0.0, 1.0)),
height: relCropSizeY.clamp(0.0, 1.0 - relCropTop.clamp(0.0, 1.0)),
);
}
}

View File

@@ -6,6 +6,8 @@ import '../../data/repositories/session_repository.dart';
import '../capture/capture_screen.dart';
import '../history/history_screen.dart';
import '../statistics/statistics_screen.dart';
import 'package:fl_chart/fl_chart.dart';
import '../../data/models/session.dart';
import 'widgets/stats_card.dart';
class HomeScreen extends StatefulWidget {
@@ -17,6 +19,7 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
Map<String, dynamic>? _stats;
List<Session> _recentSessions = [];
bool _isLoading = true;
@override
@@ -28,9 +31,12 @@ class _HomeScreenState extends State<HomeScreen> {
Future<void> _loadStats() async {
final repository = context.read<SessionRepository>();
final stats = await repository.getStatistics();
final sessions = await repository.getAllSessions();
if (mounted) {
setState(() {
_stats = stats;
_recentSessions = sessions;
_isLoading = false;
});
}
@@ -181,11 +187,12 @@ class _HomeScreenState extends State<HomeScreen> {
],
),
// --- MODIFICATION 2 : AJOUT DU GRAPHIQUE AU MILIEU ---
// --- MODIFICATION 2 : GRAPHIQUE RÉEL (Restauré) ---
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Container(
height: 150,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(AppConstants.borderRadius),
@@ -197,9 +204,20 @@ class _HomeScreenState extends State<HomeScreen> {
),
],
),
child: const Center(
child: Icon(Icons.show_chart, size: 50, color: Colors.grey),
),
child: _recentSessions.length < 2
? const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.show_chart, size: 40, color: Colors.grey),
Text(
'Pas assez de données',
style: TextStyle(color: Colors.grey, fontSize: 12),
),
],
),
)
: _buildHomeTrendChart(),
),
),
@@ -258,4 +276,38 @@ class _HomeScreenState extends State<HomeScreen> {
);
_loadStats();
}
// --- WIDGET DU GRAPHIQUE D'ACCUEIL ---
Widget _buildHomeTrendChart() {
// Trier par date et prendre les 7 dernières
final sorted = List<Session>.from(_recentSessions)
..sort((a, b) => a.createdAt.compareTo(b.createdAt));
final display =
sorted.length > 7 ? sorted.sublist(sorted.length - 7) : sorted;
return LineChart(
LineChartData(
gridData: const FlGridData(show: false),
titlesData: const FlTitlesData(show: false),
borderData: FlBorderData(show: false),
lineBarsData: [
LineChartBarData(
spots: display.asMap().entries.map((e) {
return FlSpot(e.key.toDouble(), e.value.totalScore.toDouble());
}).toList(),
isCurved: true,
color: AppTheme.primaryColor,
barWidth: 4,
isStrokeCapRound: true,
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(
show: true,
color: AppTheme.primaryColor.withOpacity(0.1),
),
),
],
),
);
}
}

View File

@@ -1,9 +1,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:fl_chart/fl_chart.dart'; // La librairie pour les courbes
import '../../core/constants/app_constants.dart';
import '../../core/theme/app_theme.dart';
import '../../data/models/session.dart';
import '../../data/repositories/session_repository.dart';
import '../../services/statistics_service.dart';
@@ -55,6 +52,28 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
);
}
List<double> _getScoreHistory() {
if (_statistics == null || _statistics!.sessions.isEmpty) return [0];
// Sort sessions by date and take last 10
final sortedSessions = List<Session>.from(_statistics!.sessions)
..sort((a, b) => a.createdAt.compareTo(b.createdAt));
return sortedSessions.map((s) => s.totalScore.toDouble()).toList();
}
List<double> _getPrecisionHistory() {
if (_statistics == null || _statistics!.sessions.isEmpty) return [0];
// We would need to calculate precision for each session individually to have a history.
// For now, let's just use the score trend as a proxy if we don't have per-session precision cached.
// Actually, let's use the scores but normalized if possible.
final sortedSessions = List<Session>.from(_statistics!.sessions)
..sort((a, b) => a.createdAt.compareTo(b.createdAt));
return sortedSessions.map((s) {
if (s.shots.isEmpty) return 0.0;
// Simple precision proxy: score / max possible (assuming 10 is max)
return (s.totalScore / (s.shots.length * 10)) * 100;
}).toList();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -120,23 +139,33 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
_buildChartSection(
'Score',
'${_statistics?.totalScore ?? 0}',
[8, 12, 10, 15, 14, 18],
_getScoreHistory(),
),
const SizedBox(height: 20),
_buildChartSection(
'Précision',
'${_statistics?.precision.precisionScore.toStringAsFixed(1)}%',
[60, 75, 70, 85, 80, 95],
_getPrecisionHistory(),
),
const SizedBox(height: 20),
_buildChartSection('Groupement moyen', '14.2 mm', [
20,
18,
22,
15,
14,
12,
]), // mm fictif pour l'exemple
_buildChartSection(
'Groupement moyen',
'${(_statistics?.precision.groupingDiameter ?? 0 * 100).toStringAsFixed(1)}%',
_getScoreHistory().map((e) => e / 10).toList(), // Proxy for grouping history
),
const SizedBox(height: 25),
// 4. DISTRIBUTION ET BIAIS (Restauré)
if (_statistics != null && _statistics!.totalShots > 0) ...[
_buildRegionalDistribution(),
const SizedBox(height: 20),
_buildQuadrantGrid(),
const SizedBox(height: 20),
if (_statistics!.regional.biasX.abs() > 0.05 ||
_statistics!.regional.biasY.abs() > 0.05)
_buildBiasWarning(),
],
const SizedBox(height: 30),
@@ -278,17 +307,20 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
}
LineChartData _mainChartData(List<double> points) {
if (points.isEmpty) points = [0];
return LineChartData(
gridData: const FlGridData(show: false),
titlesData: const FlTitlesData(show: false),
borderData: FlBorderData(show: false),
lineBarsData: [
LineChartBarData(
spots: points
.asMap()
.entries
.map((e) => FlSpot(e.key.toDouble(), e.value))
.toList(),
spots: points.length == 1
? [const FlSpot(0, 0), FlSpot(1, points[0])]
: points
.asMap()
.entries
.map((e) => FlSpot(e.key.toDouble(), e.value))
.toList(),
isCurved: true,
color: const Color(0xFF4CAF50), // Vert comme sur ton design
barWidth: 3,
@@ -302,4 +334,186 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
],
);
}
// --- NOUVEAUX WIDGETS RESTAURÉS ---
Widget _buildRegionalDistribution() {
final regional = _statistics!.regional;
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFF1E1E1E),
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Distribution Régionale',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
Row(
children: [
const Icon(Icons.explore, color: Color(0xFF1A73E8), size: 20),
const SizedBox(width: 8),
Text(
'Direction dominante : ${regional.dominantDirection}',
style: const TextStyle(color: Colors.white70, fontSize: 14),
),
],
),
const SizedBox(height: 12),
Wrap(
spacing: 8,
runSpacing: 8,
children: regional.sectorDistribution.entries
.where((e) => e.value > 0)
.map((e) {
final percentage = (e.value / _statistics!.totalShots * 100);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: const Color(0xFF1A73E8).withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: const Color(0xFF1A73E8).withOpacity(0.3)),
),
child: Text(
'${e.key}: ${e.value} (${percentage.toStringAsFixed(0)}%)',
style: const TextStyle(color: Colors.white, fontSize: 12),
),
);
}).toList(),
),
],
),
);
}
Widget _buildQuadrantGrid() {
final quadrants = _statistics!.regional.quadrantDistribution;
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFF1E1E1E),
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Répartition par Quadrant',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
AspectRatio(
aspectRatio: 1,
child: GridView.count(
crossAxisCount: 2,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: [
_buildQuadrantCell('Haut-Gauche', quadrants['Haut-Gauche'] ?? 0),
_buildQuadrantCell('Haut-Droite', quadrants['Haut-Droite'] ?? 0),
_buildQuadrantCell('Bas-Gauche', quadrants['Bas-Gauche'] ?? 0),
_buildQuadrantCell('Bas-Droite', quadrants['Bas-Droite'] ?? 0),
],
),
),
],
),
);
}
Widget _buildQuadrantCell(String label, int count) {
final percentage = (count / _statistics!.totalShots * 100);
final intensity = count / _statistics!.totalShots;
return Container(
decoration: BoxDecoration(
color: Color.lerp(
const Color(0xFF2A2A2A),
const Color(0xFF1A73E8),
intensity,
)!.withOpacity(0.8),
borderRadius: BorderRadius.circular(8),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'$count',
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text(
'${percentage.toStringAsFixed(0)}%',
style: const TextStyle(color: Colors.white70, fontSize: 12),
),
Text(
label,
style: const TextStyle(color: Colors.white54, fontSize: 10),
),
],
),
);
}
Widget _buildBiasWarning() {
final regional = _statistics!.regional;
String description = '';
if (regional.biasX.abs() > 0.05) {
description += regional.biasX > 0 ? 'vers la droite' : 'vers la gauche';
}
if (regional.biasY.abs() > 0.05) {
if (description.isNotEmpty) description += ' et ';
description += regional.biasY > 0 ? 'vers le bas' : 'vers le haut';
}
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.orange.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.orange.withOpacity(0.3)),
),
child: Row(
children: [
const Icon(Icons.warning_amber_rounded, color: Colors.orange),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Biais détecté',
style: TextStyle(
color: Colors.orange,
fontWeight: FontWeight.bold,
),
),
Text(
'Tendance $description',
style: const TextStyle(color: Colors.white70, fontSize: 13),
),
],
),
),
],
),
);
}
}