Compare commits
No commits in common. "56ae77137cc1f72d0afa60542345e0372ff4784f" and "908d94c269a2eb604cde3ebd8c3a1a08937596b2" have entirely different histories.
56ae77137c
...
908d94c269
@ -89,61 +89,107 @@ class _ItemMenuState extends State<ItemMenu> with ShowAlertDialog {
|
||||
}
|
||||
|
||||
Future<void> _getEventInfos() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final accessToken = prefs.getString("access_token") ?? "";
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var accessToken = prefs.getString("access_token") ?? "";
|
||||
String formerName = "";
|
||||
String formerDate = "";
|
||||
String formerMap = "";
|
||||
String formerImage = "";
|
||||
String formerDesc = "";
|
||||
List<String> formerTags = [];
|
||||
List<String> formerOrga = [];
|
||||
|
||||
if (accessToken.isEmpty) {
|
||||
showAlertDialog(context, "Erreur serveur", "Cache invalide");
|
||||
return;
|
||||
}
|
||||
if (accessToken.isNotEmpty) {
|
||||
var urlGet = Uri.parse("${globals.api}/events/${widget.title}");
|
||||
|
||||
final urlGet = Uri.parse("${globals.api}/events/${widget.title}");
|
||||
final responseGet = await http.get(
|
||||
urlGet,
|
||||
headers: {HttpHeaders.cookieHeader: 'access_token=$accessToken'},
|
||||
);
|
||||
var responseGet = await http.get(urlGet,
|
||||
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
|
||||
stderr.writeln('Response Get status: ${responseGet.statusCode}');
|
||||
if (responseGet.statusCode == 200) {
|
||||
stderr.writeln('Username : ${responseGet.body}');
|
||||
events =
|
||||
Events.fromJson(jsonDecode(utf8.decode(responseGet.bodyBytes)));
|
||||
id = events!.id ?? "";
|
||||
formerName = events!.name ?? "";
|
||||
formerMap = "${events!.place}" ?? "";
|
||||
formerDesc = events!.description ?? "";
|
||||
|
||||
stderr.writeln('Response Get status: ${responseGet.statusCode}');
|
||||
formerTags = List<String>.from(events!.tags as List);
|
||||
formerOrga = List<String>.from(events!.organizers as List);
|
||||
final startDate =
|
||||
DateTime.parse(events!.startDate ?? DateTime.now().toString());
|
||||
final date = DateFormat.yMd().format(startDate);
|
||||
final time = DateFormat.Hm().format(startDate);
|
||||
|
||||
if (responseGet.statusCode == 200) {
|
||||
final responseBody = utf8.decode(responseGet.bodyBytes);
|
||||
stderr.writeln('Username : $responseBody');
|
||||
final endDate =
|
||||
DateTime.parse(events!.endDate ?? DateTime.now().toString());
|
||||
|
||||
final event = Events.fromJson(jsonDecode(responseBody));
|
||||
final dateE = DateFormat.yMd().format(endDate);
|
||||
final timeE = DateFormat.Hm().format(endDate);
|
||||
if (events!.imgUrl != null) {
|
||||
formerImage = events!.imgUrl ?? "";
|
||||
}
|
||||
|
||||
final startDate =
|
||||
DateTime.parse(event.startDate ?? DateTime.now().toString());
|
||||
final endDate =
|
||||
DateTime.parse(event.endDate ?? DateTime.now().toString());
|
||||
|
||||
final formattedStartDate =
|
||||
"${DateFormat.yMd().format(startDate)} ${DateFormat.Hm().format(startDate)}";
|
||||
final formattedEndDate =
|
||||
"${DateFormat.yMd().format(endDate)} ${DateFormat.Hm().format(endDate)}";
|
||||
|
||||
setState(() {
|
||||
eventName = event.name ?? "";
|
||||
eventStartDate = "$formattedStartDate à $formattedEndDate";
|
||||
organizers = List<String>.from(event.organizers ?? []);
|
||||
place = event.place ?? "";
|
||||
imgUrl = event.imgUrl ?? "";
|
||||
eventDescription = event.description ?? "";
|
||||
tags = List<String>.from(event.tags ?? []);
|
||||
});
|
||||
formerDate = "${date} ${time} à ${dateE} ${timeE}";
|
||||
} else {
|
||||
var text = "";
|
||||
switch (responseGet.statusCode) {
|
||||
case 400:
|
||||
{
|
||||
text = "Requête mal construite";
|
||||
}
|
||||
break;
|
||||
case 406:
|
||||
{
|
||||
text = "Mot de passe incorrect";
|
||||
}
|
||||
break;
|
||||
case 404:
|
||||
{
|
||||
text = "Utilisateur inconnu";
|
||||
}
|
||||
break;
|
||||
case 403:
|
||||
{
|
||||
text = "Vous n'avez pas l'autorisation de faire cette action";
|
||||
}
|
||||
break;
|
||||
case 410:
|
||||
{
|
||||
text = "Token invalide";
|
||||
}
|
||||
break;
|
||||
case 500:
|
||||
{
|
||||
text = "Probleme interne du serveur";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
text = "Probleme d'authentification inconnu";
|
||||
}
|
||||
break;
|
||||
}
|
||||
showAlertDialog(context, "Erreur serveur", text);
|
||||
}
|
||||
} else {
|
||||
final errorMessages = {
|
||||
400: "Requête mal construite",
|
||||
406: "Mot de passe incorrect",
|
||||
404: "Utilisateur inconnu",
|
||||
403: "Vous n'avez pas l'autorisation de faire cette action",
|
||||
410: "Token invalide",
|
||||
500: "Problème interne du serveur",
|
||||
};
|
||||
|
||||
final errorMessage = errorMessages[responseGet.statusCode] ??
|
||||
"Problème d'authentification inconnu";
|
||||
showAlertDialog(context, "Erreur serveur", errorMessage);
|
||||
showAlertDialog(context, "Erreur serveur", "Cache invalide");
|
||||
}
|
||||
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
eventName = formerName;
|
||||
eventStartDate = formerDate;
|
||||
organizers = formerOrga;
|
||||
place = formerMap;
|
||||
imgUrl = formerImage;
|
||||
eventDescription = formerDesc;
|
||||
tags = formerTags;
|
||||
});
|
||||
}
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
@ -480,33 +480,65 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchField({
|
||||
required TextEditingController controller,
|
||||
required String labelText,
|
||||
required Function(String) onChanged,
|
||||
required Function() onClear,
|
||||
required List<Map<String, dynamic>> suggestions,
|
||||
required Function(Map<String, dynamic>) onSuggestionTap,
|
||||
}) {
|
||||
Padding _buildGeographicalZoneSearchField() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: controller,
|
||||
controller: inputGeo,
|
||||
decoration: InputDecoration(
|
||||
labelText: labelText,
|
||||
labelText: 'Search by geographical zone',
|
||||
border: OutlineInputBorder(),
|
||||
suffixIcon: controller.text.isEmpty
|
||||
suffixIcon: inputGeo.text.isEmpty
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () => onClear(),
|
||||
onPressed: () async {
|
||||
SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
prefs.remove("city_lat");
|
||||
prefs.remove("city_long");
|
||||
setState(() {
|
||||
inputGeo.clear(); // Clear the text field
|
||||
geographicalZone =
|
||||
''; // Reset the geographical zone state
|
||||
suggestionsGeo.clear();
|
||||
showArrow = true;
|
||||
showInputSearch =
|
||||
true; // Optionally clear suggestions
|
||||
/// Clear the filtered posts
|
||||
showInputTag = true;
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
},
|
||||
),
|
||||
),
|
||||
onChanged: onChanged,
|
||||
onChanged: (value) async {
|
||||
if (value.isNotEmpty) {
|
||||
setState(() {
|
||||
geographicalZone = value;
|
||||
searchSuggestionsGeo(value);
|
||||
});
|
||||
} else {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.remove("city_lat");
|
||||
prefs.remove("city_long");
|
||||
setState(() {
|
||||
inputGeo.clear(); // Clear the text field
|
||||
geographicalZone = ''; // Reset the geographical zone state
|
||||
suggestionsGeo.clear(); // Optionally clear suggestions
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputTag = true;
|
||||
|
||||
/// Clear the filted posts
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
}
|
||||
},
|
||||
),
|
||||
if (suggestions.isNotEmpty)
|
||||
if (suggestionsGeo.isNotEmpty)
|
||||
Container(
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
@ -515,13 +547,181 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
),
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: suggestions.length,
|
||||
itemCount: suggestionsGeo.length,
|
||||
itemBuilder: (context, index) {
|
||||
final suggestion = suggestions[index];
|
||||
return ListTile(
|
||||
title: Text(
|
||||
suggestion['name'] ?? suggestion['place_name'] ?? ''),
|
||||
onTap: () => onSuggestionTap(suggestion),
|
||||
title: Text(suggestionsGeo[index]['place_name']),
|
||||
onTap: () async {
|
||||
final latitude =
|
||||
suggestionsGeo[index]['geometry']['coordinates'][1];
|
||||
final longitude =
|
||||
suggestionsGeo[index]['geometry']['coordinates'][0];
|
||||
|
||||
setState(() {
|
||||
geographicalZone = suggestionsGeo[index]['place_name'];
|
||||
inputGeo.text = geographicalZone;
|
||||
suggestionsGeo.clear();
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputTag = true;
|
||||
});
|
||||
SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
prefs.setDouble("city_lat", latitude);
|
||||
prefs.setDouble("city_long", longitude);
|
||||
await fetchPostsByLocation();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Padding _buildTagsField() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: inputTags,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Search by tags',
|
||||
border: OutlineInputBorder(),
|
||||
suffixIcon: inputTags.text.isEmpty
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
inputTags.clear();
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
},
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
if (value.isNotEmpty) {
|
||||
setState(() {
|
||||
itemTags = value;
|
||||
searchSuggestionsByTag(value);
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
inputTags.clear();
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputGeo = true; // Optionally clear suggestions
|
||||
itemTags = ''; // Clear the text field
|
||||
|
||||
/// Clear the filted posts
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
}
|
||||
}),
|
||||
if (suggestionsTags.isNotEmpty)
|
||||
Container(
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.blue),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: suggestionsTags.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(suggestionsTags[index]['name']),
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
itemTags = suggestionsTags[index]['name'];
|
||||
inputTags.text = itemTags;
|
||||
suggestionsTags.clear();
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputGeo = true;
|
||||
});
|
||||
await fetchPostsByLocation();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Padding _buildItemZoneSearchField() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: inputItem,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Search by item',
|
||||
border: OutlineInputBorder(),
|
||||
suffixIcon: inputItem.text.isEmpty
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
inputItem.clear();
|
||||
itemName = ''; // Reset the geographical zone state
|
||||
suggestionsItem.clear();
|
||||
showDateFields = true;
|
||||
showArrow = true;
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
},
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
if (value.isNotEmpty) {
|
||||
setState(() {
|
||||
itemName = value;
|
||||
searchSuggestionsByItem(value);
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
showDateFields = true;
|
||||
showArrow = true; // Optionally clear suggestions
|
||||
inputItem.clear(); // Clear the text field
|
||||
itemName = ''; // Reset the geographical zone state
|
||||
suggestionsItem.clear();
|
||||
|
||||
/// Clear the filted posts
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
}
|
||||
}),
|
||||
if (suggestionsItem.isNotEmpty)
|
||||
Container(
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.blue),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: suggestionsItem.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(suggestionsItem[index]['name']),
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
itemName = suggestionsItem[index]['name'];
|
||||
inputItem.text = itemName;
|
||||
suggestionsItem.clear();
|
||||
showDateFields = true;
|
||||
showArrow = true;
|
||||
});
|
||||
await fetchPostsByLocation();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
@ -547,89 +747,8 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
drawer: MyDrawer(),
|
||||
body: Column(
|
||||
children: [
|
||||
if (showInputSearch)
|
||||
_buildSearchField(
|
||||
controller: inputItem,
|
||||
labelText: 'Search by item',
|
||||
onChanged: (value) {
|
||||
if (value.isNotEmpty) {
|
||||
setState(() {
|
||||
itemName = value;
|
||||
searchSuggestionsByItem(value);
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
inputItem.clear();
|
||||
itemName = '';
|
||||
suggestionsItem.clear();
|
||||
showDateFields = true;
|
||||
showArrow = true;
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
}
|
||||
},
|
||||
onClear: () {
|
||||
setState(() {
|
||||
inputItem.clear();
|
||||
itemName = '';
|
||||
suggestionsItem.clear();
|
||||
showDateFields = true;
|
||||
showArrow = true;
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
},
|
||||
suggestions: suggestionsItem,
|
||||
onSuggestionTap: (suggestion) async {
|
||||
setState(() {
|
||||
itemName = suggestion['name'];
|
||||
inputItem.text = itemName;
|
||||
suggestionsItem.clear();
|
||||
showDateFields = true;
|
||||
showArrow = true;
|
||||
});
|
||||
await fetchPostsByLocation();
|
||||
},
|
||||
),
|
||||
if ((showDateFields) && (showInputTag))
|
||||
_buildSearchField(
|
||||
controller: inputTags,
|
||||
labelText: 'Search by tags',
|
||||
onChanged: (value) {
|
||||
if (value.isNotEmpty) {
|
||||
setState(() {
|
||||
itemTags = value;
|
||||
searchSuggestionsByTag(value);
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
inputTags.clear();
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputGeo = true;
|
||||
itemTags = '';
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
}
|
||||
},
|
||||
onClear: () {
|
||||
setState(() {
|
||||
inputTags.clear();
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
},
|
||||
suggestions: suggestionsTags,
|
||||
onSuggestionTap: (suggestion) async {
|
||||
setState(() {
|
||||
itemTags = suggestion['name'];
|
||||
inputTags.text = itemTags;
|
||||
suggestionsTags.clear();
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputGeo = true;
|
||||
});
|
||||
await fetchPostsByLocation();
|
||||
},
|
||||
),
|
||||
if (showInputSearch) _buildItemZoneSearchField(),
|
||||
if ((showDateFields) && (showInputTag)) _buildTagsField(),
|
||||
if ((showDateFields) && (showArrow))
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@ -638,62 +757,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
Flexible(child: _buildDateField("end"))
|
||||
]),
|
||||
if ((showDateFields) && (showInputGeo))
|
||||
_buildSearchField(
|
||||
controller: inputGeo,
|
||||
labelText: 'Search by geographical zone',
|
||||
onChanged: (value) async {
|
||||
if (value.isNotEmpty) {
|
||||
setState(() {
|
||||
geographicalZone = value;
|
||||
searchSuggestionsGeo(value);
|
||||
});
|
||||
} else {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.remove("city_lat");
|
||||
prefs.remove("city_long");
|
||||
setState(() {
|
||||
inputGeo.clear();
|
||||
geographicalZone = '';
|
||||
suggestionsGeo.clear();
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputTag = true;
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
}
|
||||
},
|
||||
onClear: () async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.remove("city_lat");
|
||||
prefs.remove("city_long");
|
||||
setState(() {
|
||||
inputGeo.clear();
|
||||
geographicalZone = '';
|
||||
suggestionsGeo.clear();
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputTag = true;
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
},
|
||||
suggestions: suggestionsGeo,
|
||||
onSuggestionTap: (suggestion) async {
|
||||
final latitude = suggestion['geometry']['coordinates'][1];
|
||||
final longitude = suggestion['geometry']['coordinates'][0];
|
||||
setState(() {
|
||||
geographicalZone = suggestion['place_name'];
|
||||
inputGeo.text = geographicalZone;
|
||||
suggestionsGeo.clear();
|
||||
showArrow = true;
|
||||
showInputSearch = true;
|
||||
showInputTag = true;
|
||||
});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setDouble("city_lat", latitude);
|
||||
prefs.setDouble("city_long", longitude);
|
||||
await fetchPostsByLocation();
|
||||
},
|
||||
),
|
||||
_buildGeographicalZoneSearchField(),
|
||||
if (showArrow)
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user