From 635b9279764688621e2ee27bbff26fc73700a646 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 1 Jul 2024 23:49:58 +0200 Subject: [PATCH] =?UTF-8?q?itemDescription=20en=20cours=C3=A9=20'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- covas_mobile/lib/pages/ItemMenu.dart | 94 +++++++++++----------------- 1 file changed, 36 insertions(+), 58 deletions(-) diff --git a/covas_mobile/lib/pages/ItemMenu.dart b/covas_mobile/lib/pages/ItemMenu.dart index 269b5de..75dc0d9 100644 --- a/covas_mobile/lib/pages/ItemMenu.dart +++ b/covas_mobile/lib/pages/ItemMenu.dart @@ -7,13 +7,15 @@ 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 '../classes/events.dart'; void main() { - runApp(const MyApp()); + initializeDateFormatting("fr_FR", null).then((_) => (const MyApp())); } class MyApp extends StatelessWidget { @@ -62,6 +64,7 @@ class ItemMenu extends StatefulWidget { class _ItemMenuState extends State with ShowErrorDialog { String listUser = ""; String eventName = ""; + String eventStartDate = ""; Events? events; @override @@ -74,7 +77,8 @@ class _ItemMenuState extends State with ShowErrorDialog { Future _getEventInfos() async { SharedPreferences prefs = await SharedPreferences.getInstance(); var accessToken = prefs.getString("access_token") ?? ""; - String former = ""; + String formerName = ""; + String formerDate = ""; print("${accessToken}"); if (accessToken.isNotEmpty) { @@ -86,8 +90,11 @@ class _ItemMenuState extends State with ShowErrorDialog { if (responseGet.statusCode == 200) { stderr.writeln('Username : ${responseGet.body}'); var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); - print(events["name"]); - former = events["name"]; + formerName = events["name"]; + final startDate = DateTime.parse(events["start_date"]); + final date = DateFormat.yMd().format(startDate); + final time = DateFormat.Hm().format(startDate); + formerDate = "${date} - ${time}"; } else { var text = ""; switch (responseGet.statusCode) { @@ -139,8 +146,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. - eventName = former; - print(eventName); + eventName = formerName; + eventStartDate = formerDate; }); } @@ -155,61 +162,32 @@ class _ItemMenuState extends State 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("eventName : ${eventName}"), - backgroundColor: Colors.blue, - foregroundColor: Colors.white, - ), - 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 : ${eventName}"), + backgroundColor: Colors.blue, + foregroundColor: Colors.white, + ), + body: SingleChildScrollView( + child: Column( children: [ - Form( - key: _formKey, - child: Column( - children: [ - // 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: 150, + /*decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(50.0)),*/ + //child: Image.asset('asset/images/flutter-logo.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("${eventStartDate}")], + ) ], - ), - ), - // This trailing comma makes auto-formatting nicer for build methods. - ); + ))); } }