Merge pull request 'feature/itemDescription' (#3) from feature/itemDescription into main

Reviewed-on: #3
This commit is contained in:
v4l3n71n 2024-07-06 09:50:19 +02:00
commit 8f4217b881
6 changed files with 118 additions and 86 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -6,7 +6,7 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
//import 'MyHomePage.dart'; //import 'MyHomePage.dart';
import 'ListItemMenu.dart'; import 'pages/ListItemMenu.dart';
import 'classes/alert.dart'; import 'classes/alert.dart';
@ -35,10 +35,14 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
TextEditingController inputPseudo = TextEditingController(); TextEditingController inputPseudo = TextEditingController();
TextEditingController inputPassword = TextEditingController(); TextEditingController inputPassword = TextEditingController();
Future<void> _login(BuildContext context) async { Future<void> _login(BuildContext context) async {
var url = Uri.parse("http://${globals.api}/token"); var url = Uri.parse("${globals.api}/token");
var pseudo = inputPseudo.text; var pseudo = inputPseudo.text;
var password = inputPassword.text; var password = inputPassword.text;
print("get login");
print(pseudo.isNotEmpty);
print(password.isNotEmpty);
if ((pseudo.isNotEmpty) && (password.isNotEmpty)) { if ((pseudo.isNotEmpty) && (password.isNotEmpty)) {
print(url);
try { try {
//String credentials = "${pseudo}:${password}"; //String credentials = "${pseudo}:${password}";
//Codec<String, String> stringToBase64 = utf8.fuse(base64); //Codec<String, String> stringToBase64 = utf8.fuse(base64);
@ -55,7 +59,7 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
"username": "${pseudo}", "username": "${pseudo}",
"password": "${password}" "password": "${password}"
}); });
print(response.statusCode);
if ((response.statusCode == 200) || (response.statusCode == 201)) { if ((response.statusCode == 200) || (response.statusCode == 201)) {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
@ -128,12 +132,17 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
void start() async { void start() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
var access_token = prefs.getString("access_token") ?? ""; var access_token = prefs.getString("access_token") ?? "";
print("Get access token");
if (access_token.isNotEmpty) { if (access_token.isNotEmpty) {
var urlToken = Uri.parse("https://${globals.api}/token"); print("Appel HTTP");
var urlToken = Uri.parse("${globals.api}/token");
var responseToken = await http.get(urlToken, var responseToken = await http.get(urlToken,
headers: {HttpHeaders.cookieHeader: 'access_token: ${access_token}'}); headers: {HttpHeaders.cookieHeader: 'access_token: ${access_token}'});
print(responseToken.statusCode);
if (responseToken.statusCode == 200) { if (responseToken.statusCode == 200) {
print("route to item list");
Navigator.push( Navigator.push(
context, MaterialPageRoute(builder: (_) => ListItemMenu())); context, MaterialPageRoute(builder: (_) => ListItemMenu()));
} else { } else {
@ -166,11 +175,10 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
child: Container( child: Container(
width: 200, width: 200,
height: 150, height: 150,
/*decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.red, color: Colors.red,
borderRadius: BorderRadius.circular(50.0)),*/ borderRadius: BorderRadius.circular(50.0)),
//child: Image.asset('asset/images/flutter-logo.png') child: Image.asset('./images/flutter.png')),
),
), ),
), ),
Padding( Padding(

View File

@ -7,17 +7,22 @@ import 'package:covas_mobile/classes/alert.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:intl/intl.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'variable/globals.dart' as globals; import '../variable/globals.dart' as globals;
import '../classes/events.dart';
void main() { void main() {
runApp(const MyApp()); initializeDateFormatting("fr_FR", null).then((_) => (const MyApp()));
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application. // This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
@ -34,13 +39,13 @@ class MyApp extends StatelessWidget {
// is not restarted. // is not restarted.
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
), ),
home: const MyHomePage(title: 'Flutter Demo Home Page'), home: const ItemMenu(title: 'Flutter Demo Home Page'),
); );
} }
} }
class MyHomePage extends StatefulWidget { class ItemMenu extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key); const ItemMenu({Key? key, required this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning // 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 // that it has a State object (defined below) that contains fields that affect
@ -52,31 +57,59 @@ class MyHomePage extends StatefulWidget {
// always marked "final". // always marked "final".
final String title; final String title;
@override @override
State<MyHomePage> createState() => _MyHomePageState(); State<ItemMenu> createState() => _ItemMenuState();
} }
class _MyHomePageState extends State<MyHomePage> with ShowErrorDialog { class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
String listUser = ""; String listUser = "";
String eventName = "";
String eventStartDate = "";
String organizers = "";
String place = "";
Future<void> _incrementCounter() async { Events? events;
@override
void initState() {
super.initState();
_getEventInfos();
}
Future<void> _getEventInfos() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? ""; var accessToken = prefs.getString("access_token") ?? "";
String former = ""; String formerName = "";
String formerDate = "";
String formerOrga = "";
String formerMap = "";
if (accessToken.isNotEmpty) { if (accessToken.isNotEmpty) {
var urlGet = Uri.parse("http://${globals.api}/events"); var urlGet = Uri.parse("${globals.api}/events/${widget.title}");
var responseGet = await http.get(urlGet, var responseGet = await http.get(urlGet,
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
stderr.writeln('Response Get status: ${responseGet.statusCode}'); stderr.writeln('Response Get status: ${responseGet.statusCode}');
if (responseGet.statusCode == 200) { if (responseGet.statusCode == 200) {
stderr.writeln('Username : ${responseGet.body}'); stderr.writeln('Username : ${responseGet.body}');
var json = jsonDecode(utf8.decode(responseGet.bodyBytes)); var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
for (var user in json) { formerName = events["name"];
stderr.writeln('name : ${user['name']}'); formerMap = events["place"];
former = "$former\n ${user['name']} : ${user["place"]}"; final startDate = DateTime.parse(events["start_date"]);
final date = DateFormat.yMd().format(startDate);
final time = DateFormat.Hm().format(startDate);
final endDate = DateTime.parse(events["end_date"]);
final dateE = DateFormat.yMd().format(endDate);
final timeE = DateFormat.Hm().format(endDate);
formerDate = "${date} ${time} à ${dateE} ${timeE}";
if (events["organizers"].length > 1) {
formerOrga = "${events['organizers'][0]}";
for (var i = 1; i < events["organizers"].length; i++) {
formerOrga = "${formerOrga}, ${events['organizers'][i]}";
}
} else {
formerOrga = "${events['organizers'][0]}";
} }
} else { } else {
var text = ""; var text = "";
@ -129,7 +162,10 @@ class _MyHomePageState extends State<MyHomePage> with ShowErrorDialog {
// so that the display can reflect the updated values. If we changed // so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be // _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen. // called again, and so nothing would appear to happen.
listUser = former; eventName = formerName;
eventStartDate = formerDate;
organizers = formerOrga;
place = formerMap;
}); });
} }
@ -147,60 +183,41 @@ class _MyHomePageState extends State<MyHomePage> with ShowErrorDialog {
appBar: AppBar( appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by // 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. // the App.build method, and use it to set our appbar title.
title: Text(widget.title), title: Text("${eventName}"),
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
), ),
body: Center( body: SingleChildScrollView(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Form(
key: _formKey,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
// Add TextFormFields and ElevatedButton here. Padding(
TextFormField( padding: const EdgeInsets.only(top: 60.0),
// The validator receives the text that the user has entered. child: Center(
validator: (value) { child: Container(
if (value == null || value.isEmpty) { height: 250, child: Image.asset('images/flutter.png')),
return 'Please enter some text';
}
return null;
},
), ),
),
Row(
children: [
Icon(Icons.event),
Text("Date : ${eventStartDate}",
style: TextStyle(fontSize: 15.0))
], ],
), ),
), Row(children: [
const Text( Icon(Icons.explore),
'You have pushed the button this many times:', Text("Carte : ${place}", style: TextStyle(fontSize: 15.0))
), ]),
Text( Row(children: [
'$listUser', Icon(Icons.group),
style: Theme.of(context).textTheme.headlineMedium, Text("Organisateurs : ${organizers}",
), style: TextStyle(fontSize: 15.0))
]),
Row(children: [
Icon(Icons.description),
Text("Description : ", style: TextStyle(fontSize: 15.0))
])
], ],
), )));
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
} }
} }

View File

@ -1,13 +1,14 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import "ItemMenu.dart";
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'classes/events.dart'; import '../classes/events.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:intl/date_symbol_data_local.dart'; import 'package:intl/date_symbol_data_local.dart';
import 'variable/globals.dart' as globals; import '../variable/globals.dart' as globals;
// app starting point // app starting point
void main() { void main() {
@ -45,7 +46,7 @@ class _MyHomePageState extends State<ListItemMenu> {
var accessToken = prefs.getString("access_token") ?? ""; var accessToken = prefs.getString("access_token") ?? "";
final List<Events> body = []; final List<Events> body = [];
if (accessToken.isNotEmpty) { if (accessToken.isNotEmpty) {
var url = Uri.parse("http://${globals.api}/events"); var url = Uri.parse("${globals.api}/events");
final response = await http.get(url, headers: { final response = await http.get(url, headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
HttpHeaders.cookieHeader: "access_token=${accessToken}" HttpHeaders.cookieHeader: "access_token=${accessToken}"
@ -103,7 +104,13 @@ class _MyHomePageState extends State<ListItemMenu> {
return ListTile( return ListTile(
title: Text('${post.name!}'), title: Text('${post.name!}'),
subtitle: Text('${post.place!}\n${date} ${time}')); subtitle: Text('${post.place!}\n${date} ${time}'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ItemMenu(title: post.id!)));
});
}, },
separatorBuilder: (context, index) { separatorBuilder: (context, index) {
return Divider(); return Divider();

View File

@ -1 +1 @@
String api = "backend.valczeryba.ovh"; String api = "https://backend.valczeryba.ovh";

View File

@ -61,8 +61,8 @@ flutter:
uses-material-design: true uses-material-design: true
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
# assets: assets:
# - images/a_dot_burr.jpeg - images/flutter.png
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see