change alert message

This commit is contained in:
Valentin CZERYBA 2024-12-30 22:34:17 +01:00
parent 938b677b6e
commit 43d77f778b
7 changed files with 55 additions and 45 deletions

View File

@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
mixin ShowErrorDialog<T extends StatefulWidget> on State<T> {
void showErrorDialog(BuildContext context, String text) {
mixin ShowAlertDialog<T extends StatefulWidget> on State<T> {
void showAlertDialog(BuildContext context, String title, String text) {
// Create AlertDialog
AlertDialog dialog = AlertDialog(
title: Text("Error"),
title: Text(title),
content: Text(text),
actions: [
ElevatedButton(

View File

@ -32,7 +32,7 @@ class LoginDemo extends StatefulWidget {
_LoginDemoState createState() => _LoginDemoState();
}
class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
class _LoginDemoState extends State<LoginDemo> with ShowAlertDialog {
TextEditingController inputPseudo = TextEditingController();
TextEditingController inputPassword = TextEditingController();
Future<void> _login(BuildContext context) async {
@ -120,13 +120,13 @@ class _LoginDemoState extends State<LoginDemo> 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");
}
}

View File

@ -54,7 +54,7 @@ class DisplayPictureScreen extends StatefulWidget {
// A widget that displays the picture taken by the user.
class DisplayPictureScreenState extends State<DisplayPictureScreen>
with ShowDescImageAdd, ShowErrorDialog, TickerProviderStateMixin {
with ShowDescImageAdd, ShowAlertDialog, TickerProviderStateMixin {
late AnimationController controller;
@override
void initState() {
@ -80,7 +80,7 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
Future<void> 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<DisplayPictureScreen>
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);

View File

@ -52,7 +52,7 @@ class EditEvent extends StatefulWidget {
}
class _EditEventState extends State<EditEvent>
with ShowErrorDialog, ShowEventDialog {
with ShowAlertDialog, ShowEventDialog {
TextEditingController inputName = TextEditingController();
TextEditingController inputDate = TextEditingController();
@ -208,7 +208,8 @@ class _EditEventState extends State<EditEvent>
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<EditEvent>
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<EditEvent>
}
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");
}
}

View File

@ -67,7 +67,7 @@ class ItemMenu extends StatefulWidget {
State<ItemMenu> createState() => _ItemMenuState();
}
class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
class _ItemMenuState extends State<ItemMenu> with ShowAlertDialog {
String listUser = "";
String eventName = "";
String eventStartDate = "";
@ -169,10 +169,10 @@ class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
}
break;
}
showErrorDialog(context, text);
showAlertDialog(context, "Erreur serveur", text);
}
} else {
showErrorDialog(context, "Cache invalide");
showAlertDialog(context, "Erreur serveur", "Cache invalide");
}
setState(() {

View File

@ -42,7 +42,7 @@ class MapboxPages extends StatefulWidget {
State<MapboxPages> createState() => _MapboxPagesState();
}
class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
late MapboxMapController mapController;
late String mapboxAccessToken;
List<LatLng> routeCoordinates = [];
@ -63,7 +63,8 @@ class _MapboxPagesState extends State<MapboxPages> 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<MapboxPages> with ShowErrorDialog {
_handleErrorResponse(responseGet.statusCode);
}
} else {
showErrorDialog(context, "Invalid cache.");
showAlertDialog(context, "Erreur serveur", "Invalid cache.");
}
}
@ -116,14 +117,15 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
default:
text = "Unknown error.";
}
showErrorDialog(context, text);
showAlertDialog(context, "Erreur serveur", text);
}
Future<void> _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<MapboxPages> 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<MapboxPages> 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<MapboxPages> 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<MapboxPages> 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<MapboxPages> with ShowErrorDialog {
_zoomToFitRoute(routeCoordinates);
}
} else {
showErrorDialog(context, "Invalid coordinates or user position.");
showAlertDialog(context, "Erreur de coordonée",
"Invalid coordinates or user position.");
}
}

View File

@ -44,7 +44,7 @@ class UpdateeventImage extends StatefulWidget {
}
class _UpdateeventImageState extends State<UpdateeventImage>
with ShowErrorDialog, ShowEventDialog {
with ShowAlertDialog, ShowEventDialog {
TextEditingController inputName = TextEditingController();
TextEditingController inputDate = TextEditingController();
@ -156,7 +156,7 @@ class _UpdateeventImageState extends State<UpdateeventImage>
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<UpdateeventImage>
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<UpdateeventImage>
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<UpdateeventImage>
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<UpdateeventImage>
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<UpdateeventImage>
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 {