This commit is contained in:
2026-05-14 16:54:32 +00:00
parent 5b2a2e7ddb
commit 15fcbcc9eb
212 changed files with 18586 additions and 10360 deletions
@@ -1,13 +1,13 @@
class Question {
final String text;
final List<Option> options;
Question({required this.text, required this.options});
}
class Option {
final String text;
final int points;
Option({required this.text, required this.points});
}
class Question {
final String text;
final List<Option> options;
Question({required this.text, required this.options});
}
class Option {
final String text;
final int points;
Option({required this.text, required this.points});
}
@@ -1,65 +1,65 @@
import 'package:flutter/material.dart';
import '../models/question.dart';
import '../services/diagnostic_service.dart';
class DiagnosticProvider with ChangeNotifier {
final DiagnosticService _service = DiagnosticService();
List<Question> _questions = [];
int _currentQuestionIndex = 0;
int _totalScore = 0;
bool _isFinished = false;
bool _isLoading = true;
List<Question> get questions => _questions;
int get currentQuestionIndex => _currentQuestionIndex;
int get totalScore => _totalScore;
bool get isFinished => _isFinished;
bool get isLoading => _isLoading;
DiagnosticProvider() {
loadQuestions();
}
Future<void> loadQuestions() async {
_isLoading = true;
notifyListeners();
_questions = await _service.fetchStressEvents();
_isLoading = false;
notifyListeners();
}
void answerQuestion(int points) {
_totalScore += points;
if (_currentQuestionIndex < _questions.length - 1) {
_currentQuestionIndex++;
} else {
_isFinished = true;
}
notifyListeners();
}
void reset() {
_currentQuestionIndex = 0;
_totalScore = 0;
_isFinished = false;
notifyListeners();
}
String get stressLevel {
if (_totalScore < 150) return "Risque Faible";
if (_totalScore < 300) return "Risque Modéré (50%)";
return "Risque Élevé (80%)";
}
String get advice {
if (_totalScore < 150) {
return "Votre niveau de changement de vie est gérable. Continuez à maintenir votre équilibre actuel.";
}
if (_totalScore < 300) {
return "Vous avez vécu beaucoup de changements. Il y a un risque modéré que cela affecte votre santé. Prenez du temps pour vous reposer.";
}
return "Attention : Votre score est très élevé. L'accumulation de stress lié à ces changements majeurs pourrait sérieusement impacter votre santé. Il est recommandé de consulter un professionnel.";
}
}
import 'package:flutter/material.dart';
import '../models/question.dart';
import '../services/diagnostic_service.dart';
class DiagnosticProvider with ChangeNotifier {
final DiagnosticService _service = DiagnosticService();
List<Question> _questions = [];
int _currentQuestionIndex = 0;
int _totalScore = 0;
bool _isFinished = false;
bool _isLoading = true;
List<Question> get questions => _questions;
int get currentQuestionIndex => _currentQuestionIndex;
int get totalScore => _totalScore;
bool get isFinished => _isFinished;
bool get isLoading => _isLoading;
DiagnosticProvider() {
loadQuestions();
}
Future<void> loadQuestions() async {
_isLoading = true;
notifyListeners();
_questions = await _service.fetchStressEvents();
_isLoading = false;
notifyListeners();
}
void answerQuestion(int points) {
_totalScore += points;
if (_currentQuestionIndex < _questions.length - 1) {
_currentQuestionIndex++;
} else {
_isFinished = true;
}
notifyListeners();
}
void reset() {
_currentQuestionIndex = 0;
_totalScore = 0;
_isFinished = false;
notifyListeners();
}
String get stressLevel {
if (_totalScore < 150) return "Risque Faible";
if (_totalScore < 300) return "Risque Modéré (50%)";
return "Risque Élevé (80%)";
}
String get advice {
if (_totalScore < 150) {
return "Votre niveau de changement de vie est gérable. Continuez à maintenir votre équilibre actuel.";
}
if (_totalScore < 300) {
return "Vous avez vécu beaucoup de changements. Il y a un risque modéré que cela affecte votre santé. Prenez du temps pour vous reposer.";
}
return "Attention : Votre score est très élevé. L'accumulation de stress lié à ces changements majeurs pourrait sérieusement impacter votre santé. Il est recommandé de consulter un professionnel.";
}
}
@@ -1,122 +1,122 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/diagnostic_provider.dart';
class DiagnosticScreen extends StatelessWidget {
const DiagnosticScreen({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => DiagnosticProvider(),
child: const _DiagnosticView(),
);
}
}
class _DiagnosticView extends StatelessWidget {
const _DiagnosticView();
@override
Widget build(BuildContext context) {
final provider = Provider.of<DiagnosticProvider>(context);
if (provider.isLoading) {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}
if (provider.questions.isEmpty) {
return Scaffold(
appBar: AppBar(title: const Text('Diagnostic')),
body: const Center(child: Text('Aucun événement trouvé.')),
);
}
final question = provider.questions[provider.currentQuestionIndex];
if (provider.isFinished) {
return Scaffold(
appBar: AppBar(title: const Text('Résultat du Diagnostic')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Votre niveau de stress est :', style: TextStyle(fontSize: 18)),
const SizedBox(height: 10),
Text(
provider.stressLevel,
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: _getColorForLevel(provider.stressLevel),
),
),
const SizedBox(height: 20),
Text(
provider.advice,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16, fontStyle: FontStyle.italic),
),
const SizedBox(height: 40),
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: const Text('Retour à l\'accueil'),
),
],
),
),
),
);
}
return Scaffold(
appBar: AppBar(
title: Text('Question ${provider.currentQuestionIndex + 1}/${provider.questions.length}'),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
LinearProgressIndicator(
value: (provider.currentQuestionIndex + 1) / provider.questions.length,
backgroundColor: Colors.grey.shade200,
),
const SizedBox(height: 40),
Text(
question.text,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
textAlign: TextAlign.center,
),
const SizedBox(height: 40),
...question.options.map((option) => Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: ElevatedButton(
onPressed: () => provider.answerQuestion(option.points),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
child: Text(option.text),
),
)),
],
),
),
);
}
Color _getColorForLevel(String level) {
switch (level) {
case "Faible": return Colors.green;
case "Modéré": return Colors.orange;
case "Élevé": return Colors.red;
case "Très élevé": return Colors.red.shade900;
default: return Colors.black;
}
}
}
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/diagnostic_provider.dart';
class DiagnosticScreen extends StatelessWidget {
const DiagnosticScreen({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => DiagnosticProvider(),
child: const _DiagnosticView(),
);
}
}
class _DiagnosticView extends StatelessWidget {
const _DiagnosticView();
@override
Widget build(BuildContext context) {
final provider = Provider.of<DiagnosticProvider>(context);
if (provider.isLoading) {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}
if (provider.questions.isEmpty) {
return Scaffold(
appBar: AppBar(title: const Text('Diagnostic')),
body: const Center(child: Text('Aucun événement trouvé.')),
);
}
final question = provider.questions[provider.currentQuestionIndex];
if (provider.isFinished) {
return Scaffold(
appBar: AppBar(title: const Text('Résultat du Diagnostic')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Votre niveau de stress est :', style: TextStyle(fontSize: 18)),
const SizedBox(height: 10),
Text(
provider.stressLevel,
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: _getColorForLevel(provider.stressLevel),
),
),
const SizedBox(height: 20),
Text(
provider.advice,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16, fontStyle: FontStyle.italic),
),
const SizedBox(height: 40),
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: const Text('Retour à l\'accueil'),
),
],
),
),
),
);
}
return Scaffold(
appBar: AppBar(
title: Text('Question ${provider.currentQuestionIndex + 1}/${provider.questions.length}'),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
LinearProgressIndicator(
value: (provider.currentQuestionIndex + 1) / provider.questions.length,
backgroundColor: Colors.grey.shade200,
),
const SizedBox(height: 40),
Text(
question.text,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
textAlign: TextAlign.center,
),
const SizedBox(height: 40),
...question.options.map((option) => Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: ElevatedButton(
onPressed: () => provider.answerQuestion(option.points),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
child: Text(option.text),
),
)),
],
),
),
);
}
Color _getColorForLevel(String level) {
switch (level) {
case "Faible": return Colors.green;
case "Modéré": return Colors.orange;
case "Élevé": return Colors.red;
case "Très élevé": return Colors.red.shade900;
default: return Colors.black;
}
}
}
@@ -1,30 +1,30 @@
import 'package:dio/dio.dart';
import '../../../core/network/dio_client.dart';
import '../models/question.dart';
class DiagnosticService {
final Dio _dio = DioClient().dio;
Future<List<Question>> fetchStressEvents() async {
try {
final response = await _dio.get('/stress-events');
if (response.statusCode == 200) {
List<dynamic> data = response.data;
return data.map((item) {
return Question(
text: "Avez-vous vécu : ${item['event_name']} ?",
options: [
Option(text: "Oui", points: int.parse(item['points'].toString())),
Option(text: "Non", points: 0),
],
);
}).toList();
}
return [];
} catch (e) {
print("Erreur lors de la récupération des événements : $e");
return [];
}
}
}
import 'package:dio/dio.dart';
import '../../../core/network/dio_client.dart';
import '../models/question.dart';
class DiagnosticService {
final Dio _dio = DioClient().dio;
Future<List<Question>> fetchStressEvents() async {
try {
final response = await _dio.get('/stress-events');
if (response.statusCode == 200) {
List<dynamic> data = response.data;
return data.map((item) {
return Question(
text: "Avez-vous vécu : ${item['event_name']} ?",
options: [
Option(text: "Oui", points: int.parse(item['points'].toString())),
Option(text: "Non", points: 0),
],
);
}).toList();
}
return [];
} catch (e) {
print("Erreur lors de la récupération des événements : $e");
return [];
}
}
}