work in progress

This commit is contained in:
Valentin CZERYBA 2024-06-30 16:27:24 +02:00
parent e3069a1eb8
commit ce489bc86a
2 changed files with 23 additions and 16 deletions

View File

@ -136,7 +136,7 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
if (access_token.isNotEmpty) {
print("Appel HTTP");
var urlToken = Uri.parse("https://${globals.api}/token");
var urlToken = Uri.parse("${globals.api}/token");
var responseToken = await http.get(urlToken,
headers: {HttpHeaders.cookieHeader: 'access_token: ${access_token}'});

View File

@ -10,6 +10,8 @@ import 'package:shared_preferences/shared_preferences.dart';
import '../variable/globals.dart' as globals;
import '../classes/events.dart';
void main() {
runApp(const MyApp());
}
@ -18,6 +20,7 @@ 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(
@ -52,32 +55,39 @@ class ItemMenu extends StatefulWidget {
// always marked "final".
final String title;
@override
State<ItemMenu> createState() => _ItemMenuState();
}
class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
String listUser = "";
String eventName = "";
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 = "";
print("${accessToken}");
if (accessToken.isNotEmpty) {
var urlGet = Uri.parse("${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"]}";
}
Events events = jsonDecode(utf8.decode(responseGet.bodyBytes));
print(events.name);
former = events.name!;
} else {
var text = "";
switch (responseGet.statusCode) {
@ -129,7 +139,8 @@ class _ItemMenuState extends State<ItemMenu> 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 = former;
print(eventName);
});
}
@ -147,7 +158,7 @@ class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
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),
title: Text("eventName : ${eventName}"),
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
@ -198,11 +209,7 @@ class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
// This trailing comma makes auto-formatting nicer for build methods.
);
}
}