diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 3cf8376..eda0feb 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -136,7 +136,7 @@ class _LoginDemoState extends State 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}'}); diff --git a/covas_mobile/lib/pages/ItemMenu.dart b/covas_mobile/lib/pages/ItemMenu.dart index ce5434e..748f62d 100644 --- a/covas_mobile/lib/pages/ItemMenu.dart +++ b/covas_mobile/lib/pages/ItemMenu.dart @@ -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 createState() => _ItemMenuState(); } class _ItemMenuState extends State with ShowErrorDialog { String listUser = ""; + String eventName = ""; - Future _incrementCounter() async { + Events? events; + @override + void initState() { + super.initState(); + + _getEventInfos(); + } + + Future _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 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 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 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. ); } }