2024-06-30 13:32:36 +02:00
|
|
|
// ignore_for_file: unnecessary_brace_in_string_interps
|
|
|
|
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:covas_mobile/classes/alert.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2024-07-01 23:49:58 +02:00
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:intl/date_symbol_data_local.dart';
|
2024-06-30 13:32:36 +02:00
|
|
|
|
2024-06-30 15:17:10 +02:00
|
|
|
import '../variable/globals.dart' as globals;
|
2024-06-30 13:32:36 +02:00
|
|
|
|
2024-06-30 16:27:24 +02:00
|
|
|
import '../classes/events.dart';
|
|
|
|
|
2024-08-08 23:39:56 +02:00
|
|
|
import 'ListItemMenu.dart';
|
|
|
|
|
2024-06-30 13:32:36 +02:00
|
|
|
void main() {
|
2024-07-01 23:49:58 +02:00
|
|
|
initializeDateFormatting("fr_FR", null).then((_) => (const MyApp()));
|
2024-06-30 13:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
// This widget is the root of your application.
|
2024-06-30 16:27:24 +02:00
|
|
|
|
2024-06-30 13:32:36 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Flutter Demo',
|
|
|
|
theme: ThemeData(
|
|
|
|
// This is the theme of your application.
|
|
|
|
//
|
|
|
|
// Try running your application with "flutter run". You'll see the
|
|
|
|
// application has a blue toolbar. Then, without quitting the app, try
|
|
|
|
// changing the primarySwatch below to Colors.green and then invoke
|
|
|
|
// "hot reload" (press "r" in the console where you ran "flutter run",
|
|
|
|
// or simply save your changes to "hot reload" in a Flutter IDE).
|
|
|
|
// Notice that the counter didn't reset back to zero; the application
|
|
|
|
// is not restarted.
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
),
|
|
|
|
home: const ItemMenu(title: 'Flutter Demo Home Page'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ItemMenu extends StatefulWidget {
|
|
|
|
const ItemMenu({Key? key, required this.title}) : super(key: key);
|
|
|
|
|
|
|
|
// This widget is the home page of your application. It is stateful, meaning
|
|
|
|
// that it has a State object (defined below) that contains fields that affect
|
|
|
|
// how it looks.
|
|
|
|
|
|
|
|
// This class is the configuration for the state. It holds the values (in this
|
|
|
|
// case the title) provided by the parent (in this case the App widget) and
|
|
|
|
// used by the build method of the State. Fields in a Widget subclass are
|
|
|
|
// always marked "final".
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
@override
|
|
|
|
State<ItemMenu> createState() => _ItemMenuState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
|
|
|
|
String listUser = "";
|
2024-06-30 16:27:24 +02:00
|
|
|
String eventName = "";
|
2024-07-01 23:49:58 +02:00
|
|
|
String eventStartDate = "";
|
2024-09-25 23:08:28 +02:00
|
|
|
String eventDescription = "";
|
2024-07-06 09:43:35 +02:00
|
|
|
String place = "";
|
2024-09-17 23:50:23 +02:00
|
|
|
String imgUrl = "";
|
2024-10-20 11:32:33 +02:00
|
|
|
List<String> tags = [];
|
2024-10-20 18:23:34 +02:00
|
|
|
List<String> organizers = [];
|
2024-06-30 16:27:24 +02:00
|
|
|
|
|
|
|
Events? events;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
_getEventInfos();
|
|
|
|
}
|
2024-06-30 13:32:36 +02:00
|
|
|
|
2024-06-30 16:27:24 +02:00
|
|
|
Future<void> _getEventInfos() async {
|
2024-06-30 13:32:36 +02:00
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
var accessToken = prefs.getString("access_token") ?? "";
|
2024-07-01 23:49:58 +02:00
|
|
|
String formerName = "";
|
|
|
|
String formerDate = "";
|
2024-07-06 09:43:35 +02:00
|
|
|
String formerMap = "";
|
2024-09-17 23:50:23 +02:00
|
|
|
String formerImage = "";
|
2024-09-25 23:08:28 +02:00
|
|
|
String formerDesc = "";
|
2024-10-20 11:32:33 +02:00
|
|
|
List<String> formerTags = [];
|
2024-10-20 18:23:34 +02:00
|
|
|
List<String> formerOrga = [];
|
2024-06-30 13:32:36 +02:00
|
|
|
|
|
|
|
if (accessToken.isNotEmpty) {
|
2024-06-30 16:27:24 +02:00
|
|
|
var urlGet = Uri.parse("${globals.api}/events/${widget.title}");
|
2024-06-30 13:32:36 +02:00
|
|
|
|
|
|
|
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}');
|
2024-07-01 21:53:53 +02:00
|
|
|
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
2024-07-01 23:49:58 +02:00
|
|
|
formerName = events["name"];
|
2024-09-25 23:08:28 +02:00
|
|
|
formerMap =
|
|
|
|
"${events["place"]} - ${events["zip_code"]} ${events["city"]} - ${events["country"]}";
|
|
|
|
formerDesc = events["description"];
|
2024-10-20 11:32:33 +02:00
|
|
|
formerTags = List<String>.from(events['tags'] as List);
|
2024-10-20 18:23:34 +02:00
|
|
|
formerOrga = List<String>.from(events['organizers'] as List);
|
2024-07-01 23:49:58 +02:00
|
|
|
final startDate = DateTime.parse(events["start_date"]);
|
|
|
|
final date = DateFormat.yMd().format(startDate);
|
|
|
|
final time = DateFormat.Hm().format(startDate);
|
2024-07-06 00:10:12 +02:00
|
|
|
|
|
|
|
final endDate = DateTime.parse(events["end_date"]);
|
2024-09-17 23:50:23 +02:00
|
|
|
|
2024-07-06 00:10:12 +02:00
|
|
|
final dateE = DateFormat.yMd().format(endDate);
|
|
|
|
final timeE = DateFormat.Hm().format(endDate);
|
2024-09-17 23:50:23 +02:00
|
|
|
if (events["imgUrl"] != null) {
|
|
|
|
formerImage = events["imgUrl"];
|
|
|
|
}
|
|
|
|
|
2024-07-06 00:10:12 +02:00
|
|
|
formerDate = "${date} ${time} à ${dateE} ${timeE}";
|
2024-06-30 13:32:36 +02:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
showErrorDialog(context, text);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showErrorDialog(context, "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.
|
2024-07-01 23:49:58 +02:00
|
|
|
eventName = formerName;
|
|
|
|
eventStartDate = formerDate;
|
2024-07-06 00:10:12 +02:00
|
|
|
organizers = formerOrga;
|
2024-07-06 09:43:35 +02:00
|
|
|
place = formerMap;
|
2024-09-17 23:50:23 +02:00
|
|
|
imgUrl = formerImage;
|
2024-09-25 23:08:28 +02:00
|
|
|
eventDescription = formerDesc;
|
2024-10-20 11:32:33 +02:00
|
|
|
tags = formerTags;
|
2024-06-30 13:32:36 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
// This method is rerun every time setState is called, for instance as done
|
|
|
|
// by the _incrementCounter method above.
|
|
|
|
//
|
|
|
|
// The Flutter framework has been optimized to make rerunning build methods
|
|
|
|
// fast, so that you can just rebuild anything that needs updating rather
|
|
|
|
// than having to individually change instances of widgets.
|
|
|
|
return Scaffold(
|
2024-07-01 23:49:58 +02:00
|
|
|
appBar: AppBar(
|
2024-08-08 23:39:56 +02:00
|
|
|
// Here we take the value from the MyHomePage object that was created by
|
|
|
|
// the App.build method, and use it to set our appbar title.
|
|
|
|
title: Text("${eventName}"),
|
|
|
|
backgroundColor: Colors.blue,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(Icons.arrow_back),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context, MaterialPageRoute(builder: (_) => ListItemMenu()));
|
|
|
|
},
|
|
|
|
)),
|
2024-07-01 23:49:58 +02:00
|
|
|
body: SingleChildScrollView(
|
|
|
|
child: Column(
|
2024-06-30 13:32:36 +02:00
|
|
|
children: <Widget>[
|
2024-07-01 23:49:58 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 60.0),
|
|
|
|
child: Center(
|
2024-09-17 23:50:23 +02:00
|
|
|
child: Container(height: 250, child: Image.network(imgUrl)),
|
2024-06-30 13:32:36 +02:00
|
|
|
),
|
|
|
|
),
|
2024-09-29 12:52:02 +02:00
|
|
|
Row(children: [
|
|
|
|
Icon(Icons.event),
|
|
|
|
Text(
|
|
|
|
"Date : ",
|
|
|
|
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
|
|
|
|
)
|
|
|
|
]),
|
2024-07-01 23:49:58 +02:00
|
|
|
Row(
|
2024-07-05 23:54:39 +02:00
|
|
|
children: [
|
2024-09-29 12:52:02 +02:00
|
|
|
Flexible(
|
|
|
|
child: Text("${eventStartDate}",
|
|
|
|
style: TextStyle(fontSize: 15.0)))
|
2024-07-05 23:54:39 +02:00
|
|
|
],
|
|
|
|
),
|
2024-07-06 09:43:35 +02:00
|
|
|
Row(children: [
|
|
|
|
Icon(Icons.explore),
|
2024-09-29 12:52:02 +02:00
|
|
|
Text(
|
|
|
|
"Carte : ",
|
|
|
|
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
Row(children: [
|
2024-09-29 11:02:27 +02:00
|
|
|
Flexible(
|
2024-09-29 12:52:02 +02:00
|
|
|
child: Text("${place}",
|
2024-09-29 11:02:27 +02:00
|
|
|
style: TextStyle(fontSize: 15.0),
|
|
|
|
maxLines: 3,
|
|
|
|
overflow: TextOverflow.ellipsis))
|
2024-07-06 09:43:35 +02:00
|
|
|
]),
|
2024-07-05 23:54:39 +02:00
|
|
|
Row(children: [
|
|
|
|
Icon(Icons.group),
|
2024-09-29 12:52:02 +02:00
|
|
|
Text(
|
|
|
|
"Organisateurs : ",
|
|
|
|
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
Row(children: [
|
2024-10-20 18:23:34 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 8,
|
|
|
|
bottom: 8,
|
|
|
|
left: 8,
|
|
|
|
),
|
|
|
|
child: Wrap(
|
|
|
|
runSpacing: 4.0,
|
|
|
|
spacing: 4.0,
|
|
|
|
direction: Axis.vertical,
|
|
|
|
children: organizers.map((String tag) {
|
|
|
|
return Container(
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(20.0),
|
|
|
|
),
|
|
|
|
color: Colors.blue,
|
|
|
|
),
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 5.0),
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 10.0, vertical: 5.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
InkWell(
|
|
|
|
child: Text(
|
|
|
|
'$tag',
|
|
|
|
style: const TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList()),
|
|
|
|
),
|
2024-07-05 23:54:39 +02:00
|
|
|
]),
|
|
|
|
Row(children: [
|
|
|
|
Icon(Icons.description),
|
2024-09-29 12:35:52 +02:00
|
|
|
Text("Description : ",
|
|
|
|
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold))
|
|
|
|
]),
|
|
|
|
Row(children: [
|
2024-09-29 11:02:27 +02:00
|
|
|
Flexible(
|
2024-09-29 12:35:52 +02:00
|
|
|
child: Text("${eventDescription}",
|
2024-09-29 11:02:27 +02:00
|
|
|
style: TextStyle(fontSize: 15.0),
|
|
|
|
maxLines: 3,
|
|
|
|
overflow: TextOverflow.ellipsis))
|
2024-10-20 11:32:33 +02:00
|
|
|
]),
|
|
|
|
Row(children: [
|
|
|
|
Icon(Icons.category),
|
|
|
|
Text("Tags : ",
|
|
|
|
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold))
|
|
|
|
]),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 8,
|
|
|
|
bottom: 8,
|
|
|
|
left: 8,
|
|
|
|
),
|
|
|
|
child: Wrap(
|
|
|
|
runSpacing: 4.0,
|
|
|
|
spacing: 4.0,
|
2024-10-20 11:46:51 +02:00
|
|
|
direction: Axis.vertical,
|
2024-10-20 11:32:33 +02:00
|
|
|
children: tags.map((String tag) {
|
|
|
|
return Container(
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(20.0),
|
|
|
|
),
|
|
|
|
color: Colors.blue,
|
|
|
|
),
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 5.0),
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 10.0, vertical: 5.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
InkWell(
|
|
|
|
child: Text(
|
|
|
|
'$tag',
|
|
|
|
style: const TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList()),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2024-06-30 13:32:36 +02:00
|
|
|
],
|
2024-07-01 23:49:58 +02:00
|
|
|
)));
|
2024-06-30 13:32:36 +02:00
|
|
|
}
|
|
|
|
}
|