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 'MyHomePage.dart';
import 'ListItemMenu.dart';
import 'pages/ListItemMenu.dart';
import 'classes/alert.dart';
@ -35,10 +35,14 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
TextEditingController inputPseudo = TextEditingController();
TextEditingController inputPassword = TextEditingController();
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 password = inputPassword.text;
print("get login");
print(pseudo.isNotEmpty);
print(password.isNotEmpty);
if ((pseudo.isNotEmpty) && (password.isNotEmpty)) {
print(url);
try {
//String credentials = "${pseudo}:${password}";
//Codec<String, String> stringToBase64 = utf8.fuse(base64);
@ -55,7 +59,7 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
"username": "${pseudo}",
"password": "${password}"
});
print(response.statusCode);
if ((response.statusCode == 200) || (response.statusCode == 201)) {
SharedPreferences prefs = await SharedPreferences.getInstance();
@ -128,12 +132,17 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
void start() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var access_token = prefs.getString("access_token") ?? "";
print("Get access token");
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,
headers: {HttpHeaders.cookieHeader: 'access_token: ${access_token}'});
print(responseToken.statusCode);
if (responseToken.statusCode == 200) {
print("route to item list");
Navigator.push(
context, MaterialPageRoute(builder: (_) => ListItemMenu()));
} else {
@ -164,13 +173,12 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
padding: const EdgeInsets.only(top: 60.0),
child: Center(
child: Container(
width: 200,
height: 150,
/*decoration: BoxDecoration(
width: 200,
height: 150,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(50.0)),*/
//child: Image.asset('asset/images/flutter-logo.png')
),
borderRadius: BorderRadius.circular(50.0)),
child: Image.asset('./images/flutter.png')),
),
),
Padding(

View File

@ -7,17 +7,22 @@ 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';
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() {
runApp(const MyApp());
initializeDateFormatting("fr_FR", null).then((_) => (const MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
@ -34,13 +39,13 @@ class MyApp extends StatelessWidget {
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
home: const ItemMenu(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
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
@ -52,31 +57,59 @@ class MyHomePage extends StatefulWidget {
// always marked "final".
final String title;
@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 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();
var accessToken = prefs.getString("access_token") ?? "";
String former = "";
String formerName = "";
String formerDate = "";
String formerOrga = "";
String formerMap = "";
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,
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
stderr.writeln('Response Get status: ${responseGet.statusCode}');
if (responseGet.statusCode == 200) {
stderr.writeln('Username : ${responseGet.body}');
var json = jsonDecode(utf8.decode(responseGet.bodyBytes));
for (var user in json) {
stderr.writeln('name : ${user['name']}');
former = "$former\n ${user['name']} : ${user["place"]}";
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
formerName = events["name"];
formerMap = events["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 {
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
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
listUser = former;
eventName = formerName;
eventStartDate = formerDate;
organizers = formerOrga;
place = formerMap;
});
}
@ -144,63 +180,44 @@ class _MyHomePageState extends State<MyHomePage> with ShowErrorDialog {
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// 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(widget.title),
),
body: Center(
// 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,
appBar: AppBar(
// 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,
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Form(
key: _formKey,
child: Column(
children: <Widget>[
// Add TextFormFields and ElevatedButton here.
TextFormField(
// The validator receives the text that the user has entered.
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
],
Padding(
padding: const EdgeInsets.only(top: 60.0),
child: Center(
child: Container(
height: 250, child: Image.asset('images/flutter.png')),
),
),
const Text(
'You have pushed the button this many times:',
),
Text(
'$listUser',
style: Theme.of(context).textTheme.headlineMedium,
Row(
children: [
Icon(Icons.event),
Text("Date : ${eventStartDate}",
style: TextStyle(fontSize: 15.0))
],
),
Row(children: [
Icon(Icons.explore),
Text("Carte : ${place}", style: TextStyle(fontSize: 15.0))
]),
Row(children: [
Icon(Icons.group),
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:io';
import "ItemMenu.dart";
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'classes/events.dart';
import '../classes/events.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;
// app starting point
void main() {
@ -45,7 +46,7 @@ class _MyHomePageState extends State<ListItemMenu> {
var accessToken = prefs.getString("access_token") ?? "";
final List<Events> body = [];
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: {
"Content-Type": "application/json",
HttpHeaders.cookieHeader: "access_token=${accessToken}"
@ -103,7 +104,13 @@ class _MyHomePageState extends State<ListItemMenu> {
return ListTile(
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) {
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
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
assets:
- images/flutter.png
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see