itemDescription en coursé

'
This commit is contained in:
Valentin CZERYBA 2024-07-01 23:49:58 +02:00
parent 2c6a1a1686
commit 635b927976

View File

@ -7,13 +7,15 @@ 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'; 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 {
@ -62,6 +64,7 @@ class ItemMenu extends StatefulWidget {
class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog { class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
String listUser = ""; String listUser = "";
String eventName = ""; String eventName = "";
String eventStartDate = "";
Events? events; Events? events;
@override @override
@ -74,7 +77,8 @@ class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
Future<void> _getEventInfos() async { 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 = "";
print("${accessToken}"); print("${accessToken}");
if (accessToken.isNotEmpty) { if (accessToken.isNotEmpty) {
@ -86,8 +90,11 @@ class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
if (responseGet.statusCode == 200) { if (responseGet.statusCode == 200) {
stderr.writeln('Username : ${responseGet.body}'); stderr.writeln('Username : ${responseGet.body}');
var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
print(events["name"]); formerName = events["name"];
former = 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 { } else {
var text = ""; var text = "";
switch (responseGet.statusCode) { switch (responseGet.statusCode) {
@ -139,8 +146,8 @@ class _ItemMenuState extends State<ItemMenu> 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.
eventName = former; eventName = formerName;
print(eventName); eventStartDate = formerDate;
}); });
} }
@ -155,61 +162,32 @@ class _ItemMenuState extends State<ItemMenu> with ShowErrorDialog {
// fast, so that you can just rebuild anything that needs updating rather // fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets. // than having to individually change instances of widgets.
return Scaffold( return Scaffold(
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("eventName : ${eventName}"), title: Text("eventName : ${eventName}"),
backgroundColor: Colors.blue, backgroundColor: Colors.blue,
foregroundColor: Colors.white, foregroundColor: Colors.white,
), ),
body: Center( body: SingleChildScrollView(
// Center is a layout widget. It takes a single child and positions it child: Column(
// 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>[ children: <Widget>[
Form( Padding(
key: _formKey, padding: const EdgeInsets.only(top: 60.0),
child: Column( child: Center(
children: <Widget>[ child: Container(
// Add TextFormFields and ElevatedButton here. height: 150,
TextFormField( /*decoration: BoxDecoration(
// The validator receives the text that the user has entered. color: Colors.red,
validator: (value) { borderRadius: BorderRadius.circular(50.0)),*/
if (value == null || value.isEmpty) { //child: Image.asset('asset/images/flutter-logo.png')
return 'Please enter some text'; ),
}
return null;
},
),
],
), ),
), ),
const Text( Row(
'You have pushed the button this many times:', children: [Icon(Icons.event), Text("${eventStartDate}")],
), )
Text(
'$listUser',
style: Theme.of(context).textTheme.headlineMedium,
),
], ],
), )));
),
// This trailing comma makes auto-formatting nicer for build methods.
);
} }
} }