diff --git a/covas_mobile/images/flutter.png b/covas_mobile/images/flutter.png new file mode 100644 index 0000000..e02f153 Binary files /dev/null and b/covas_mobile/images/flutter.png differ diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 817a956..1db7c0d 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -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 with ShowErrorDialog { TextEditingController inputPseudo = TextEditingController(); TextEditingController inputPassword = TextEditingController(); Future _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 stringToBase64 = utf8.fuse(base64); @@ -55,7 +59,7 @@ class _LoginDemoState extends State 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 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 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( diff --git a/covas_mobile/lib/MyHomePage.dart b/covas_mobile/lib/pages/ItemMenu.dart similarity index 56% rename from covas_mobile/lib/MyHomePage.dart rename to covas_mobile/lib/pages/ItemMenu.dart index 95879f8..63f83b7 100644 --- a/covas_mobile/lib/MyHomePage.dart +++ b/covas_mobile/lib/pages/ItemMenu.dart @@ -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 createState() => _MyHomePageState(); + State createState() => _ItemMenuState(); } -class _MyHomePageState extends State with ShowErrorDialog { +class _ItemMenuState extends State with ShowErrorDialog { String listUser = ""; + String eventName = ""; + String eventStartDate = ""; + String organizers = ""; + String place = ""; - 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 = ""; + 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 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 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: [ - 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: 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. - ); + ))); } } diff --git a/covas_mobile/lib/ListItemMenu.dart b/covas_mobile/lib/pages/ListItemMenu.dart similarity index 89% rename from covas_mobile/lib/ListItemMenu.dart rename to covas_mobile/lib/pages/ListItemMenu.dart index eea0e64..31ee70a 100644 --- a/covas_mobile/lib/ListItemMenu.dart +++ b/covas_mobile/lib/pages/ListItemMenu.dart @@ -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 { var accessToken = prefs.getString("access_token") ?? ""; final List 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 { 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(); diff --git a/covas_mobile/lib/variable/globals.dart b/covas_mobile/lib/variable/globals.dart index 30de4ad..f90fa4d 100644 --- a/covas_mobile/lib/variable/globals.dart +++ b/covas_mobile/lib/variable/globals.dart @@ -1 +1 @@ -String api = "backend.valczeryba.ovh"; +String api = "https://backend.valczeryba.ovh"; diff --git a/covas_mobile/pubspec.yaml b/covas_mobile/pubspec.yaml index 1356f4a..2865742 100644 --- a/covas_mobile/pubspec.yaml +++ b/covas_mobile/pubspec.yaml @@ -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