From 43d77f778b36ab203db32519b213109819f3fba4 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 30 Dec 2024 22:34:17 +0100 Subject: [PATCH] change alert message --- covas_mobile/lib/classes/alert.dart | 6 ++-- covas_mobile/lib/main.dart | 8 ++--- .../lib/pages/DisplayPictureScreen.dart | 11 +++---- covas_mobile/lib/pages/EditEvent.dart | 20 +++++++------ covas_mobile/lib/pages/ItemMenu.dart | 6 ++-- covas_mobile/lib/pages/MapboxPages.dart | 30 +++++++++++-------- covas_mobile/lib/pages/UpdateEventImage.dart | 19 +++++++----- 7 files changed, 55 insertions(+), 45 deletions(-) diff --git a/covas_mobile/lib/classes/alert.dart b/covas_mobile/lib/classes/alert.dart index 7ca853a..28a03e9 100644 --- a/covas_mobile/lib/classes/alert.dart +++ b/covas_mobile/lib/classes/alert.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; -mixin ShowErrorDialog on State { - void showErrorDialog(BuildContext context, String text) { +mixin ShowAlertDialog on State { + void showAlertDialog(BuildContext context, String title, String text) { // Create AlertDialog AlertDialog dialog = AlertDialog( - title: Text("Error"), + title: Text(title), content: Text(text), actions: [ ElevatedButton( diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index be4b083..4e58520 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -32,7 +32,7 @@ class LoginDemo extends StatefulWidget { _LoginDemoState createState() => _LoginDemoState(); } -class _LoginDemoState extends State with ShowErrorDialog { +class _LoginDemoState extends State with ShowAlertDialog { TextEditingController inputPseudo = TextEditingController(); TextEditingController inputPassword = TextEditingController(); Future _login(BuildContext context) async { @@ -120,13 +120,13 @@ class _LoginDemoState extends State with ShowErrorDialog { } break; } - showErrorDialog(context, text); + showAlertDialog(context, "Erreur serveur", text); } } catch (e) { - showErrorDialog(context, "${e}"); + showAlertDialog(context, "Erreur", "${e}"); } } else { - showErrorDialog(context, "Champ vide"); + showAlertDialog(context, "Erreur", "Champ vide"); } } diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index b50aaa2..19631a1 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -54,7 +54,7 @@ class DisplayPictureScreen extends StatefulWidget { // A widget that displays the picture taken by the user. class DisplayPictureScreenState extends State - with ShowDescImageAdd, ShowErrorDialog, TickerProviderStateMixin { + with ShowDescImageAdd, ShowAlertDialog, TickerProviderStateMixin { late AnimationController controller; @override void initState() { @@ -80,7 +80,7 @@ class DisplayPictureScreenState extends State Future displayError(String e) async { print("problem gemini : ${e}"); - showErrorDialog(context, + showAlertDialog(context, 'Error IA', "L'IA de Google n'a pas su analyser l'image. Recommecer avec une autre"); } @@ -119,14 +119,15 @@ class DisplayPictureScreenState extends State builder: (_) => ItemMenu(title: events[0]["id"]))); } } else { - showErrorDialog(context, + showAlertDialog(context, 'Erreur de reponse', "response status code update : ${responseGet.statusCode}"); } } else { - showErrorDialog(context, "Erreur de token"); + showAlertDialog(context, "Erreur de reponse", "Erreur de token"); } } catch (e) { - showErrorDialog(context, "Erreur de format de donnée fourni par l'IA"); + showAlertDialog( + context, "Erreur IA", "Erreur de format de donnée fourni par l'IA"); } //showDescImageAddDialog(context, message); diff --git a/covas_mobile/lib/pages/EditEvent.dart b/covas_mobile/lib/pages/EditEvent.dart index 3f95af3..e1b9275 100644 --- a/covas_mobile/lib/pages/EditEvent.dart +++ b/covas_mobile/lib/pages/EditEvent.dart @@ -52,7 +52,7 @@ class EditEvent extends StatefulWidget { } class _EditEventState extends State - with ShowErrorDialog, ShowEventDialog { + with ShowAlertDialog, ShowEventDialog { TextEditingController inputName = TextEditingController(); TextEditingController inputDate = TextEditingController(); @@ -208,7 +208,8 @@ class _EditEventState extends State var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); if (events.length > 0) { if (events[0]["id"] != widget.events!.id) { - showErrorDialog(context, "Evenement deja existant"); + showAlertDialog( + context, "Info evenement", "Evenement deja existant"); } return; @@ -236,7 +237,7 @@ class _EditEventState extends State final status = res.statusCode; print("code status imgbb ${status}"); if (status != 200) { - showErrorDialog(context, "Image non posté"); + showAlertDialog(context, "Erreur image", "Image non posté"); return; } var body = json.decode(utf8.decode(res.bodyBytes)); @@ -306,22 +307,23 @@ class _EditEventState extends State } break; } - showErrorDialog(context, text); + showAlertDialog(context, "Erreur serveur", text); } } else { - showErrorDialog(context, "Aucune donnée geographique"); + showAlertDialog( + context, "Erreur serveur", "Aucune donnée geographique"); } } else { - showErrorDialog(context, "Mapbox non accessible"); + showAlertDialog(context, "Erreur serveur", "Mapbox non accessible"); } } catch (e) { - showErrorDialog(context, "${e}"); + showAlertDialog(context, "Erreur serveur", "${e}"); } } else { - showErrorDialog(context, "Champ vide"); + showAlertDialog(context, "Erreur utilisateur", "Champ vide"); } } else { - showErrorDialog(context, "Evenement non futur"); + showAlertDialog(context, "Erreur evenement", "Evenement non futur"); } } diff --git a/covas_mobile/lib/pages/ItemMenu.dart b/covas_mobile/lib/pages/ItemMenu.dart index daafdc8..b1d4995 100644 --- a/covas_mobile/lib/pages/ItemMenu.dart +++ b/covas_mobile/lib/pages/ItemMenu.dart @@ -67,7 +67,7 @@ class ItemMenu extends StatefulWidget { State createState() => _ItemMenuState(); } -class _ItemMenuState extends State with ShowErrorDialog { +class _ItemMenuState extends State with ShowAlertDialog { String listUser = ""; String eventName = ""; String eventStartDate = ""; @@ -169,10 +169,10 @@ class _ItemMenuState extends State with ShowErrorDialog { } break; } - showErrorDialog(context, text); + showAlertDialog(context, "Erreur serveur", text); } } else { - showErrorDialog(context, "Cache invalide"); + showAlertDialog(context, "Erreur serveur", "Cache invalide"); } setState(() { diff --git a/covas_mobile/lib/pages/MapboxPages.dart b/covas_mobile/lib/pages/MapboxPages.dart index cd9f7a7..8f26b90 100644 --- a/covas_mobile/lib/pages/MapboxPages.dart +++ b/covas_mobile/lib/pages/MapboxPages.dart @@ -42,7 +42,7 @@ class MapboxPages extends StatefulWidget { State createState() => _MapboxPagesState(); } -class _MapboxPagesState extends State with ShowErrorDialog { +class _MapboxPagesState extends State with ShowAlertDialog { late MapboxMapController mapController; late String mapboxAccessToken; List routeCoordinates = []; @@ -63,7 +63,8 @@ class _MapboxPagesState extends State with ShowErrorDialog { void _initToken() { mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; if (mapboxAccessToken.isEmpty) { - showErrorDialog(context, "Mapbox Access Token is not available."); + showAlertDialog( + context, "Erreur Mapbox", "Mapbox Access Token is not available."); } } @@ -88,7 +89,7 @@ class _MapboxPagesState extends State with ShowErrorDialog { _handleErrorResponse(responseGet.statusCode); } } else { - showErrorDialog(context, "Invalid cache."); + showAlertDialog(context, "Erreur serveur", "Invalid cache."); } } @@ -116,14 +117,15 @@ class _MapboxPagesState extends State with ShowErrorDialog { default: text = "Unknown error."; } - showErrorDialog(context, text); + showAlertDialog(context, "Erreur serveur", text); } Future _getUserLocation() async { try { bool serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { - showErrorDialog(context, "Location services are disabled."); + showAlertDialog( + context, "Erreur de service", "Location services are disabled."); return; } @@ -131,13 +133,14 @@ class _MapboxPagesState extends State with ShowErrorDialog { if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.denied) { - showErrorDialog(context, "Location permissions are denied."); + showAlertDialog(context, "Erreur de permission", + "Location permissions are denied."); return; } } if (permission == LocationPermission.deniedForever) { - showErrorDialog(context, + showAlertDialog(context, "Erreur de permission", "Location permissions are permanently denied. Enable them in settings."); return; } @@ -171,7 +174,7 @@ class _MapboxPagesState extends State with ShowErrorDialog { _initToken(); _getEventInfo(); } catch (e) { - showErrorDialog(context, "Failed to get user location: $e"); + showAlertDialog(context, "Erreur geo", "Failed to get user location: $e"); } } @@ -191,8 +194,8 @@ class _MapboxPagesState extends State with ShowErrorDialog { }).toList(); }); } else { - showErrorDialog( - context, "Failed to fetch the route: ${response.statusCode}"); + showAlertDialog(context, "Erreur serveur", + "Failed to fetch the route: ${response.statusCode}"); } } @@ -244,8 +247,8 @@ class _MapboxPagesState extends State with ShowErrorDialog { currentRouteLine = null; } if (!isUserPositionInitialized) { - showErrorDialog( - context, "User position is not yet initialized. Try again."); + showAlertDialog(context, "Erreur de position", + "User position is not yet initialized. Try again."); return; } @@ -284,7 +287,8 @@ class _MapboxPagesState extends State with ShowErrorDialog { _zoomToFitRoute(routeCoordinates); } } else { - showErrorDialog(context, "Invalid coordinates or user position."); + showAlertDialog(context, "Erreur de coordonée", + "Invalid coordinates or user position."); } } diff --git a/covas_mobile/lib/pages/UpdateEventImage.dart b/covas_mobile/lib/pages/UpdateEventImage.dart index 83a1c85..46270dc 100644 --- a/covas_mobile/lib/pages/UpdateEventImage.dart +++ b/covas_mobile/lib/pages/UpdateEventImage.dart @@ -44,7 +44,7 @@ class UpdateeventImage extends StatefulWidget { } class _UpdateeventImageState extends State - with ShowErrorDialog, ShowEventDialog { + with ShowAlertDialog, ShowEventDialog { TextEditingController inputName = TextEditingController(); TextEditingController inputDate = TextEditingController(); @@ -156,7 +156,7 @@ class _UpdateeventImageState extends State var endDate = "${endDateFormat}T${endTimepicker.text.replaceAll('-', ':')}"; if (!startDateCompare.isAfter(dateNow)) { - showErrorDialog(context, "Evenement non futur"); + showAlertDialog(context, "Erreur evenement", "Evenement non futur"); return; } @@ -164,7 +164,7 @@ class _UpdateeventImageState extends State var accessToken = prefs.getString("access_token") ?? ""; if (accessToken.isEmpty) { - showErrorDialog(context, "Token d'accès manquant"); + showAlertDialog(context, "Erreur token", "Token d'accès manquant"); return; } @@ -179,13 +179,14 @@ class _UpdateeventImageState extends State final searchboxResponse = await http.get(searchboxUrl); if (searchboxResponse.statusCode != 200) { - showErrorDialog(context, "Erreur lors de la géocodage avec Searchbox"); + showAlertDialog(context, "Erreur map", + "Erreur lors de la géocodage avec Searchbox"); return; } final searchboxData = json.decode(searchboxResponse.body); if (searchboxData['results'].isEmpty) { - showErrorDialog(context, "Lieu introuvable"); + showAlertDialog(context, "Erreur", "Lieu introuvable"); return; } @@ -229,7 +230,8 @@ class _UpdateeventImageState extends State await http.Response.fromStream(await imgbbRequest.send()); if (imgbbResponse.statusCode != 200) { - showErrorDialog(context, "Erreur lors de l'upload d'image"); + showAlertDialog( + context, "Erreur serveur", "Erreur lors de l'upload d'image"); return; } @@ -265,7 +267,7 @@ class _UpdateeventImageState extends State handleHttpError(eventResponse.statusCode, context); } } catch (e) { - showErrorDialog(context, "Erreur: ${e.toString()}"); + showAlertDialog(context, "Erreur", "Erreur: ${e.toString()}"); } } @@ -279,7 +281,8 @@ class _UpdateeventImageState extends State 410: "Token invalide", 500: "Problème interne du serveur", }; - showErrorDialog(context, errorMessages[statusCode] ?? "Erreur inconnue"); + showAlertDialog(context, "Erreur serveur", + errorMessages[statusCode] ?? "Erreur inconnue"); } void start() async {