From 6f9249ea0e706b778fde1e51fb96afd69afa86ba Mon Sep 17 00:00:00 2001 From: Enzo Date: Wed, 22 Nov 2023 11:07:24 +0100 Subject: [PATCH 1/6] modif en cours --- lib/main.dart | 3 ++- lib/modele/manager_file.dart | 16 ++++++++++++++ .../list_activity_utile.dart | 3 +++ lib/view/activity/web/web_list_activity.dart | 2 +- lib/view/test/page_test.dart | 21 ++++++++++++------- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index e1b9afd..16f2c89 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'package:provider/provider.dart'; import 'package:smartfit_app_mobile/modele/user.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/view/login/signup_view.dart'; +import 'package:smartfit_app_mobile/view/test/page_test.dart'; void main() { runApp(ChangeNotifierProvider( @@ -36,7 +37,7 @@ class MyApp extends StatelessWidget { primaryColor: TColor.primaryColor1, fontFamily: "Poppins"), //home: const StartedView(), - home: const SignUpView(), + home: const TestPage(), ); } } diff --git a/lib/modele/manager_file.dart b/lib/modele/manager_file.dart index a9ee7d2..bf29f85 100644 --- a/lib/modele/manager_file.dart +++ b/lib/modele/manager_file.dart @@ -55,6 +55,22 @@ class ManagerFile { return true; } + // -- Check si le fichier existe localement -- // + Future fileExist(String filname) async { + Directory directory = Directory("${await localPath}\\Files\\"); + if (!directory.existsSync()) { + print("Le dossier n'existe pas !"); + return false; + } + List files = directory.listSync(); + for (FileSystemEntity file in files) { + if (file.path.split("\\").last == filname) { + return true; + } + } + return false; + } + // --- Ligne utile --- // //final csv = const ListToCsvConverter().convert(fitFile.toRows()); //await outFile.writeAsString(csv);*/ diff --git a/lib/modele/utile/list_activity.dart/list_activity_utile.dart b/lib/modele/utile/list_activity.dart/list_activity_utile.dart index 23da587..a5809c3 100644 --- a/lib/modele/utile/list_activity.dart/list_activity_utile.dart +++ b/lib/modele/utile/list_activity.dart/list_activity_utile.dart @@ -13,6 +13,9 @@ class ListActivityUtile { final ManagerFile _managerFile = ManagerFile(); Future getContentOnTheFirstFileMobile(BuildContext context) async { + String fileUuid = + Provider.of(context, listen: false).listActivity[0].fileUuid; + Tuple2 result = await _strategy.getFile( Provider.of(context, listen: false).token, Provider.of(context, listen: false).listActivity[0].fileUuid); diff --git a/lib/view/activity/web/web_list_activity.dart b/lib/view/activity/web/web_list_activity.dart index 36c74c7..357c437 100644 --- a/lib/view/activity/web/web_list_activity.dart +++ b/lib/view/activity/web/web_list_activity.dart @@ -47,7 +47,7 @@ class _WebListActivityState extends State { }*/ void addFile(html.File file) async { - FileReader reader = html.FileReader(); + final reader = html.FileReader(); reader.readAsArrayBuffer(file); reader.onLoadEnd.listen((event) async { if (reader.readyState == html.FileReader.DONE) { diff --git a/lib/view/test/page_test.dart b/lib/view/test/page_test.dart index d1e7cfb..c46837a 100644 --- a/lib/view/test/page_test.dart +++ b/lib/view/test/page_test.dart @@ -1,4 +1,4 @@ -/*import 'dart:convert'; +import 'dart:convert'; import 'package:crypto/crypto.dart'; import 'package:flutter/foundation.dart' show kIsWeb; @@ -79,7 +79,9 @@ class _TestPage extends State { FilePickerResult? result; IDataStrategy strategy = RequestApi(); String platforme = getPlatforme(); + final ManagerFile _managerFile = ManagerFile(); + /* //late File x = File(file.path); Future readFile() async { ManagerFile x = ManagerFile(); @@ -100,7 +102,7 @@ class _TestPage extends State { //print(x.getAltitudeWithTime(ActivityOfUser(result))); //print(x.getSpeedWithTime(ActivityOfUser(result))); } - } + }*/ Future createUser() async { String mds = "1234"; @@ -194,6 +196,10 @@ class _TestPage extends State { print(res.item2); } + void lunch() { + print(_managerFile.fileExist("lol")); + } + @override Widget build(BuildContext context) { User w = context.watch(); @@ -228,8 +234,7 @@ class _TestPage extends State { onPressed: createUser, child: const Text("Create User")), ElevatedButton( onPressed: deleteUser, child: const Text("Delete User")), - ElevatedButton( - onPressed: readFile, child: const Text("ReadFile")), + ElevatedButton(onPressed: () {}, child: const Text("ReadFile")), ElevatedButton(onPressed: getFiles, child: const Text("getFiles")), ElevatedButton( onPressed: modifAttribut, child: const Text("modif attribut")), @@ -242,7 +247,9 @@ class _TestPage extends State { Text(platforme), Text(w.email), Text(context.watch().username), - Text(Provider.of(context).username) + Text(Provider.of(context).username), + const Text("-----------------------------"), + ElevatedButton(onPressed: lunch, child: const Text("Lunch !!")), ], ), ); @@ -410,6 +417,4 @@ class _MyHomePageState extends State { } <<<<<<<< HEAD:lib/view/test/page_test.dart }*/ -======== -} -*/ + From bdc1a79d85778ff787539faaa0fd98a1199d0e00 Mon Sep 17 00:00:00 2001 From: Enzo Date: Thu, 23 Nov 2023 16:03:59 +0100 Subject: [PATCH 2/6] fit into cvs --- lib/main.dart | 1 - lib/modele/manager_file.dart | 8 +- lib/modele/name_attribut_user.dart | 6 - .../activity/mobile/mobile_list_activity.dart | 3 + lib/view/page_test.dart | 406 ------------------ lib/view/test/page_test.dart | 108 ++++- 6 files changed, 104 insertions(+), 428 deletions(-) delete mode 100644 lib/modele/name_attribut_user.dart delete mode 100644 lib/view/page_test.dart diff --git a/lib/main.dart b/lib/main.dart index 16f2c89..e65a005 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smartfit_app_mobile/modele/user.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart'; -import 'package:smartfit_app_mobile/view/login/signup_view.dart'; import 'package:smartfit_app_mobile/view/test/page_test.dart'; void main() { diff --git a/lib/modele/manager_file.dart b/lib/modele/manager_file.dart index bf29f85..e88f28b 100644 --- a/lib/modele/manager_file.dart +++ b/lib/modele/manager_file.dart @@ -45,15 +45,17 @@ class ManagerFile { return directory.path; } + /* // --- A modifier si utilisé --- // - Future writeFile(String nameFileWithExtension, File file) async { + Future saveFileLocal(String nameFileWithExtension, String path) async { + /* final outFile = File("${await localPath}\\Files\\$nameFileWithExtension"); if (outFile.existsSync() == false) { outFile.createSync(recursive: true); } await outFile.writeAsString(await file.readAsString()); - return true; - } + return true;*/ + }*/ // -- Check si le fichier existe localement -- // Future fileExist(String filname) async { diff --git a/lib/modele/name_attribut_user.dart b/lib/modele/name_attribut_user.dart deleted file mode 100644 index f8a5361..0000000 --- a/lib/modele/name_attribut_user.dart +++ /dev/null @@ -1,6 +0,0 @@ -class AttributUser { - final String _email = "email"; - final String _username = "username"; - String get email => _email; - String get username => _username; -} diff --git a/lib/view/activity/mobile/mobile_list_activity.dart b/lib/view/activity/mobile/mobile_list_activity.dart index 91987cc..936e531 100644 --- a/lib/view/activity/mobile/mobile_list_activity.dart +++ b/lib/view/activity/mobile/mobile_list_activity.dart @@ -48,6 +48,9 @@ class _MobileListActivity extends State { }*/ void addFile(String path) async { + // --- Save Local + + // --- BDD Tuple2 result = await strategy.uploadFile( Provider.of(context, listen: false).token, File(path)); if (result.item1 == false) { diff --git a/lib/view/page_test.dart b/lib/view/page_test.dart deleted file mode 100644 index e0a2ee4..0000000 --- a/lib/view/page_test.dart +++ /dev/null @@ -1,406 +0,0 @@ -/* -import 'dart:convert'; -import 'package:crypto/crypto.dart'; -import 'package:csv/csv.dart'; -import 'package:flutter/material.dart'; -import 'package:path_provider/path_provider.dart'; -import 'package:file_picker/file_picker.dart'; -import 'dart:io'; - -import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart'; -import 'package:smartfit_app_mobile/modele/api/request_api.dart'; -import 'package:smartfit_app_mobile/modele/manager_file.dart'; -import 'package:tuple/tuple.dart'; - -// ----------- File --------------- // - -// Dossier de l'application -Future get _localPath async { - final directory = await getApplicationDocumentsDirectory(); - return directory.path; -} - -// Uri du fichier -Future get _localFile async { - final path = await _localPath; - return File('$path/counter.txt'); -} - -Future writeCounter(int counter) async { - final file = await _localFile; - // Write the file - return file.writeAsString('$counter'); -} - -Future readCounter() async { - try { - final file = await _localFile; - - // Read the file - final contents = await file.readAsString(); - - return int.parse(contents); - } catch (e) { - // If encountering an error, return 0 - return 0; - } -} - -String getPlatforme() { - if (kIsWeb) { - return "Web"; - } - if (Platform.isAndroid) { - return "Android"; - } - if (Platform.isWindows) { - return "Windows"; - } - if (Platform.isMacOS) { - return "MacOS"; - } - return "Null"; -} - -// File picker - -// ------------------------------------------------- // - -class TestPage extends StatefulWidget { - const TestPage({Key? key}) : super(key: key); - - @override - State createState() => _TestPage(); -} - -class _TestPage extends State { - // Lire un fichier avec picker - FilePickerResult? result; - IDataStrategy strategy = RequestApi(); - String platforme = getPlatforme(); - - //late File x = File(file.path); - Future readFile() async { - ManagerFile x = ManagerFile(); - PlatformFile t = result!.files.single; - String? y = t.path; - if (t.path == null) { - print("t"); - } else { - List result = await x.readFitFile(y!); - - //print(x.getDistanceWithTime(ActivityOfUser(result))); - //print(x.getDistance(ActivityOfUser(result))); - //print(x.getAltitudeWithTime(ActivityOfUser(result))); - //print(x.getSpeedWithTime(ActivityOfUser(result))); - final csv = const ListToCsvConverter().convert(result.cast()); - File f = File(await x.localPath + "/fit2.csv"); - f.createSync(); - await f.writeAsString(csv); - } - } - - Future createUser() async { - String mds = "1234"; - var byte = utf8.encode(mds); - var digest = sha256.convert(byte); - print(digest.toString()); - print("Appel"); - Tuple2 res = - await strategy.postUser("toto@gmail.com", digest.toString(), "toto"); - print(res.item1); - print(res.item2); - } - - Future login() async { - String mds = "1234"; - var byte = utf8.encode(mds); - var digest = sha256.convert(byte); - print(digest.toString()); - print("Appel"); - Tuple2 res = - await strategy.connexion("1234", digest.toString()); - print(res.item1); - print(res.item2); - } - - Future deleteUser() async { - String token = - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1dWlkIjoiYjA3OThmMjAtN2ZiMy0xMWVlLWJhZmQtMDI0MjBhNWEwMDFmIiwiZXhwIjoxNzA0ODgyNDI3fQ.2_bnvEC7_pwchielF3Kpu9fFtXDv_KabdOU8T07UnWI"; - print("Appel"); - Tuple2 res = await strategy.deleteUser(token); - print(res.item1); - print(res.item2); - } - - Future getFiles() async { - String token = - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1dWlkIjoiOGJiNDdmMDAtODJkNi0xMWVlLTkzMTMtMDI0MjBhNWEwMDFmIiwiZXhwIjoxNzA1MjI4MTUyfQ.9ADC65f2rNI_llytvhA6tX0NM9_O3-2RlwPXqV0yYcI"; - print("Appel"); - Tuple2 res = await strategy.getFiles(token); - print(res.item1); - print(res.item2); - } - - Future modifAttribut() async { - String nameAtt = "username"; - String newValue = "toto2"; - String token = - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1dWlkIjoiOGUyYWVmMTItN2ZiNC0xMWVlLWJhZmQtMDI0MjBhNWEwMDFmIiwiZXhwIjoxNzA0ODgzMDM4fQ.umN7LmUDbKUOeIToLcsOUIioQ7u4wsReHggRDB68VPQ"; - print("Appel"); - Tuple2 res = await strategy.modifAttribut(token, nameAtt, newValue); - print(res.item1); - print(res.item2); - } - - Future uploadFile() async { - PlatformFile t = result!.files.single; - String token = - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1dWlkIjoiOGJiNDdmMDAtODJkNi0xMWVlLTkzMTMtMDI0MjBhNWEwMDFmIiwiZXhwIjoxNzA1MjI4MTUyfQ.9ADC65f2rNI_llytvhA6tX0NM9_O3-2RlwPXqV0yYcI"; - String? lol = t.path!; - print("Appel"); - Tuple2 res = await strategy.uploadFile(token, File(lol)); - print(res.item1); - print(res.item2); - } - - Future getOneFile() async { - String ui = "fc6e234c-7fc6-11ee-bafd-02420a5a001f"; - String token = - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1dWlkIjoiOGUyYWVmMTItN2ZiNC0xMWVlLWJhZmQtMDI0MjBhNWEwMDFmIiwiZXhwIjoxNzA0ODgzOTE3fQ.TUdrGEo7A0auQlUfO5RQm874QWuGXFBSKbJ8qTGPF2M"; - print("Appel"); - Tuple2 res = await strategy.getFile(token, ui); - print(res.item1); - print(res.item2); - - ManagerFile x = ManagerFile(); - File file = File("${await x.localPath}/Walking_2023-11-08T10_57_28.fit"); - await file.create(); - await file.writeAsBytes(res.item2); - print(await x.localPath); - print("Save"); - - print(await x - .readFitFile("${await x.localPath}/Walking_2023-11-08T10_57_28.fit")); - } - - Future getInfoUser() async { - String token = - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1dWlkIjoiOGUyYWVmMTItN2ZiNC0xMWVlLWJhZmQtMDI0MjBhNWEwMDFmIiwiZXhwIjoxNzA0ODgzOTE3fQ.TUdrGEo7A0auQlUfO5RQm874QWuGXFBSKbJ8qTGPF2M"; - Tuple2 res = await strategy.getInfoUser(token); - print(res.item1); - print(res.item2); - } - - @override - Widget build(BuildContext context) { - User w = context.watch(); - - return Scaffold( - body: Column( - children: [ - const Text('A random AWESOME idea:'), - const Text("User"), - - // ↓ Add this. - ElevatedButton( - onPressed: () { - print('button pressed!'); - }, - child: Text('Next'), - ), - ElevatedButton( - onPressed: () async { - result = await FilePicker.platform.pickFiles(); - if (result == null) { - print("No file selected"); - } else { - for (var element in result!.files) { - print(element.name); - } - } - }, - child: const Text("File - ")), - ElevatedButton(onPressed: login, child: const Text("Connexion")), - ElevatedButton( - onPressed: createUser, child: const Text("Create User")), - ElevatedButton( - onPressed: deleteUser, child: const Text("Delete User")), - ElevatedButton(onPressed: readFile, child: const Text("ReadFile")), - ElevatedButton(onPressed: getFiles, child: const Text("getFiles")), - ElevatedButton( - onPressed: modifAttribut, child: const Text("modif attribut")), - ElevatedButton( - onPressed: uploadFile, child: const Text("Upload File")), - ElevatedButton( - onPressed: getOneFile, child: const Text("Get One File")), - ElevatedButton( - onPressed: getInfoUser, child: const Text("Get info User")), - Text(platforme), - Text(w.email), - Text(context.watch().username), - Text(Provider.of(context).username) - ], - ), - ); - } -} - - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - // 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 - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // 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. - _counter++; - }); - } - - void _updateText(String text) { - setState(() { - test = text; - }); - } - - IDataStrategy tmp = RequestApi(); - //late Future val = tmp.GetFile("x", "x"); - late Future val = tmp.test(); - final TextEditingController _controller = TextEditingController(); - String test = "Null"; - - @override - Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. - return Scaffold( - appBar: AppBar( - // TRY THIS: Try changing the color here to a specific color (to - // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar - // change color while the other colors stay the same. - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - // 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. - // - // 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). - // - // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" - // action in the IDE, or press "p" in the console), to see the - // wireframe for each widget. - - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text('TEST'), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), - FutureBuilder( - future: val, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.hasData) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [Text(snapshot.data!)], - ); - } - } else { - return const Text("FAIL"); - } - }, - ) - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. - body: Container( - alignment: Alignment.center, - padding: const EdgeInsets.all(8), - child: FutureBuilder( - future: val, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.hasData) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(snapshot.data!), - Text(test), - TextField( - controller: _controller, - decoration: const InputDecoration( - hintText: 'Enter Title', - ), - ), - ElevatedButton( - onPressed: () { - _updateText(_controller.text); - }, - child: const Text('Update Data'), - ), - ElevatedButton( - onPressed: () { - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => const TestPage())); - }, - child: const Text("Changer de page")) - ], - ); - } else if (snapshot.hasError) { - return Text('${snapshot.error}'); - } - } - - return const CircularProgressIndicator(); - }, - ), - ), - ); - } -} -*/ \ No newline at end of file diff --git a/lib/view/test/page_test.dart b/lib/view/test/page_test.dart index c46837a..d4e677b 100644 --- a/lib/view/test/page_test.dart +++ b/lib/view/test/page_test.dart @@ -1,6 +1,8 @@ import 'dart:convert'; import 'package:crypto/crypto.dart'; +import 'package:csv/csv.dart'; +import 'package:fit_tool/fit_tool.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; @@ -81,7 +83,6 @@ class _TestPage extends State { String platforme = getPlatforme(); final ManagerFile _managerFile = ManagerFile(); - /* //late File x = File(file.path); Future readFile() async { ManagerFile x = ManagerFile(); @@ -90,19 +91,102 @@ class _TestPage extends State { if (t.path == null) { print("t"); } else { - List result = await x.readFitFile(y!); - print("test11"); - print(result); - print("test22"); - print(ActivityOfUser(result).getHeartRateWithTime()); - print("test33"); - Provider.of(context, listen: false).addActivity(ActivityOfUser(result)); + File file = File(y!); + final content = await file.readAsBytes(); + FitFile fitFile = FitFile.fromBytes(content); + //print(fitFile.toRows()); + print("--------------"); + print("--------------"); + print("--------------"); + + print("${await _managerFile.localPath}\\test.csv"); + final outFile = File("${await _managerFile.localPath}\\test.csv"); + //final csv = const ListToCsvConverter().convert(fitFile.toRows()); + //await outFile.writeAsString(csv); + + // ----------- Lire le fit et extarire les données qu'on choisi ----------- // + List liste = fitFile.records; + List allowedField = [ + "timestamp", + "position_lat", + "position_long", + "distance" + ]; + List>> dataResult = + List.empty(growable: true); + + for (Record element in liste) { + List listeField = element.toRow(); + Map> ligneDataResult = {}; + bool skip = true; + + if (listeField[0] != "Data") { + continue; + } + + for (int i = 0; i < listeField.length;) { + if (allowedField.contains(listeField[i])) { + Map tmp = {}; + tmp["Value"] = listeField[i + 1].toString(); + tmp["Unite"] = listeField[i + 2].toString(); + ligneDataResult[listeField[i]] = tmp; + i += 2; + skip = false; + } + i += 1; + } + if (!skip) { + dataResult.add(ligneDataResult); + } + } + /* + for (var x in dataResult) { + print(x["timestamp"]!["Value"]); + }*/ + // -------------------------------- Fin ------------------------- // + // ------- Création du csv ----- // + // --- Création de l'entête -- // + List enteteCSV = []; + for (String field in allowedField) { + enteteCSV.add("Value_$field"); + enteteCSV.add("Unite_$field"); + } + + List> csvData = List.empty(growable: true); + // + for (Map> ligne in dataResult) { + List tmpLigne = List.empty(growable: true); + for (String field in allowedField) { + if (!ligne.containsKey(field)) { + tmpLigne.add("null"); + tmpLigne.add("null"); + } else { + tmpLigne.add(ligne[field]!["Value"]!); + tmpLigne.add(ligne[field]!["Unite"]!); + } + } + csvData.add(tmpLigne); + } + csvData.insert(0, enteteCSV); + + final csv = const ListToCsvConverter().convert(csvData); + await outFile.writeAsString(csv); + + // ------- FIN --------------- // + + //List result = await x.readFitFile(y!); + //print("test11"); + //print(result); + //print("test22"); + //print(ActivityOfUser(result).getHeartRateWithTime()); + //print("test33"); + //Provider.of(context, listen: false).addActivity(ActivityOfUser(result)); //print(x.getDistanceWithTime(ActivityOfUser(result))); //print(x.getDistance(ActivityOfUser(result))); //print(x.getAltitudeWithTime(ActivityOfUser(result))); //print(x.getSpeedWithTime(ActivityOfUser(result))); } - }*/ + } Future createUser() async { String mds = "1234"; @@ -196,8 +280,8 @@ class _TestPage extends State { print(res.item2); } - void lunch() { - print(_managerFile.fileExist("lol")); + void lunch() async { + print(await _managerFile.fileExist("lol")); } @override @@ -224,7 +308,7 @@ class _TestPage extends State { print("No file selected"); } else { for (var element in result!.files) { - print(element.name); + readFile(); } } }, From b99b62dc2f120fd4413352d389ff8b044b91c70a Mon Sep 17 00:00:00 2001 From: Enzo Date: Fri, 24 Nov 2023 10:55:27 +0100 Subject: [PATCH 3/6] avancement --- lib/main.dart | 5 +- lib/modele/activity.dart | 71 ++++++++--- lib/modele/api/request_api.dart | 4 +- lib/modele/manager_file.dart | 113 ++++++++++++++++-- .../list_activity_utile.dart | 10 +- .../activity/mobile/mobile_list_activity.dart | 61 +++++++--- lib/view/test/page_test.dart | 6 +- 7 files changed, 218 insertions(+), 52 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index e65a005..bea8be1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,9 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smartfit_app_mobile/modele/user.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart'; +import 'package:smartfit_app_mobile/modele/utile/signup_user.dart'; +import 'package:smartfit_app_mobile/view/login/login_view.dart'; +import 'package:smartfit_app_mobile/view/login/signup_view.dart'; import 'package:smartfit_app_mobile/view/test/page_test.dart'; void main() { @@ -36,7 +39,7 @@ class MyApp extends StatelessWidget { primaryColor: TColor.primaryColor1, fontFamily: "Poppins"), //home: const StartedView(), - home: const TestPage(), + home: const SignUpView(), ); } } diff --git a/lib/modele/activity.dart b/lib/modele/activity.dart index fba97fd..58eb5cd 100644 --- a/lib/modele/activity.dart +++ b/lib/modele/activity.dart @@ -1,6 +1,7 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:smartfit_app_mobile/common_widget/graph/graph.dart'; +import 'package:smartfit_app_mobile/modele/manager_file.dart'; class ActivityOfUser { // A afficher @@ -10,14 +11,20 @@ class ActivityOfUser { late String _nameFile; // ------------ // late String _imageName; - late List _contentActivity; - late int _dataSession; + late List> _contentActivity; + Map enteteCSV = {}; + + // ManagerFile for the field + final ManagerFile _managerFile = ManagerFile(); // -- Getter/Setter -- // - List get contentActivity => _contentActivity; - set contentActivity(List content) { + List> get contentActivity => _contentActivity; + set contentActivity(List> content) { _contentActivity = content; - _dataSession = getDataSession(); + for (int i = 0; i < content.first.length; i++) { + enteteCSV.addAll({content.first[i]: i}); + } + _contentActivity.removeAt(0); } String get fileUuid => _fileUuid; @@ -39,18 +46,33 @@ class ActivityOfUser { } } - // ----- Retourne l'indice de la ligne qui contient les données de la session -- // - int getDataSession() { - for (int i = _contentActivity.length - 1; i != 0; i--) { - if (_contentActivity[i][0] == "Data" && - _contentActivity[i][2] == "session") { - return i; - } + // ----------------- BPM ------------------ // + +// Retourne le Temps+BPM (Fichier CSV) + List getHeartRateWithTime() { + List result = List.empty(growable: true); + int firstTimestamp = int.parse(contentActivity + .first[enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!]); + + result.add(FlSpot( + (firstTimestamp ~/ 100).toDouble(), + double.parse(contentActivity + .first[enteteCSV["Value_${_managerFile.fielBPM}"]!]))); + + for (int i = 1; i < contentActivity.length; i++) { + result.add(FlSpot( + ((int.parse(contentActivity[i][ + enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!]) - + firstTimestamp) ~/ + 100) + .toDouble(), + double.parse(contentActivity[i] + [enteteCSV["Value_${_managerFile.fielBPM}"]!]))); } - return 0; + return result; } - // ----------------- BPM ------------------ // + /* List getHeartRateWithTime() { List result = List.empty(growable: true); int firtTimeStamp = 0; @@ -75,8 +97,23 @@ class ActivityOfUser { } } return result; + }*/ + + // Retourne le BPM Max (Fichier CSV) + int getMaxBpm() { + int max = int.parse( + contentActivity.first[enteteCSV["Value_${_managerFile.fielBPM}"]!]); + for (int i = 1; i < contentActivity.length; i++) { + int valueTmp = int.parse( + contentActivity[i][enteteCSV["Value_${_managerFile.fielBPM}"]!]); + if (valueTmp > max) { + max = valueTmp; + } + } + return 0; } + /* int getMaxBpm() { for (int i = 0; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "max_heart_rate") { @@ -84,7 +121,7 @@ class ActivityOfUser { } } return 0; - } + }*/ int getMinBpm() { for (int i = 0; i < _contentActivity[_dataSession].length; i++) { @@ -104,7 +141,7 @@ class ActivityOfUser { return 0; } // -------------------------- FIN BPM ---------------------- // - + /* // ---------------------- Distance ---------------------- // List getDistanceWithTime() { List result = List.empty(growable: true); @@ -304,7 +341,7 @@ class ActivityOfUser { } } return list; - } + }*/ // -------------------------- FIN Localisation ---------------------- // diff --git a/lib/modele/api/request_api.dart b/lib/modele/api/request_api.dart index 8d0756f..07673b9 100644 --- a/lib/modele/api/request_api.dart +++ b/lib/modele/api/request_api.dart @@ -37,7 +37,8 @@ class RequestApi extends IDataStrategy { @override Future> deleteFile(String token, String fileUuid) async { - final response = await http.delete(Uri.parse('$urlApi/user/files'), + final response = await http.delete( + Uri.parse('$urlApi/user/files/$fileUuid'), headers: {'Authorization': token}); if (response.statusCode == 200) { @@ -146,6 +147,7 @@ class RequestApi extends IDataStrategy { } } + // -- Priviligié uploadFileByte -- // @override Future> uploadFile(String token, File file) async { String filename = file.path.split('/').last; diff --git a/lib/modele/manager_file.dart b/lib/modele/manager_file.dart index e88f28b..1a58ee9 100644 --- a/lib/modele/manager_file.dart +++ b/lib/modele/manager_file.dart @@ -1,11 +1,108 @@ import 'dart:convert'; -import 'dart:io'; import 'dart:typed_data'; import 'package:csv/csv.dart'; import 'package:fit_tool/fit_tool.dart'; import 'package:path_provider/path_provider.dart'; class ManagerFile { + // -- Field + final String _fieldTimestamp = "timestamp"; + final String _fieldPositionLatitue = "position_lat"; + final String _fieldPositionLongitude = "position_long"; + final String _fieldDistance = "distance"; + final String _fieldBPM = "heart_rate"; + // -- Getter field + String get fieldTimeStamp => _fieldTimestamp; + String get fieldPositionLatitude => _fieldPositionLatitue; + String get fieldPositionLongitude => _fieldPositionLongitude; + String get fieldDistance => _fieldDistance; + String get fielBPM => _fieldBPM; + + List allowedFieldWalking = List.empty(growable: true); + + ManagerFile() { + allowedFieldWalking = [ + _fieldTimestamp, + _fieldPositionLatitue, + _fieldPositionLongitude, + _fieldDistance, + _fieldBPM + ]; + } + + List> convertBytesFitFileIntoCSVList(Uint8List bytes) { + FitFile fitFile = FitFile.fromBytes(bytes); + + // ----------- Lire le fit et extarire les données qu'on choisi ----------- // + List>> dataResult = + List.empty(growable: true); + + for (Record element in fitFile.records) { + List listeField = element.toRow(); + Map> ligneDataResult = {}; + bool skip = true; + + if (listeField[0] != "Data") { + continue; + } + + for (int i = 0; i < listeField.length;) { + if (allowedFieldWalking.contains(listeField[i])) { + Map tmp = {}; + tmp["Value"] = listeField[i + 1].toString(); + tmp["Unite"] = listeField[i + 2].toString(); + ligneDataResult[listeField[i]] = tmp; + i += 2; + skip = false; + } + i += 1; + } + if (!skip) { + dataResult.add(ligneDataResult); + } + } + // -------- FIN ---------- // + + // ------- Création du csv ----- // + // --- Création de l'entête -- // + List enteteCSV = []; + for (String field in allowedFieldWalking) { + enteteCSV.add("Value_$field"); + enteteCSV.add("Unite_$field"); + } + + List> csvData = List.empty(growable: true); + // + for (Map> ligne in dataResult) { + List tmpLigne = List.empty(growable: true); + for (String field in allowedFieldWalking) { + if (!ligne.containsKey(field)) { + tmpLigne.add("null"); + tmpLigne.add("null"); + } else { + tmpLigne.add(ligne[field]!["Value"]!); + tmpLigne.add(ligne[field]!["Unite"]!); + } + } + csvData.add(tmpLigne); + } + csvData.insert(0, enteteCSV); + // ------- FIN --------------- // + return csvData; + } + + // -- Read the byte of file CSV -- // + List> convertByteIntoCSV(Uint8List bytes) { + return const CsvToListConverter().convert(utf8.decode(bytes)); + } + + // ------------- Get The path of application --- // + Future get localPath async { + final directory = await getApplicationDocumentsDirectory(); + return directory.path; + } + + /* // ----- Read csv File ------- // Future> readCSVFile(String path) async { if (File(path).exists() == false) return List.empty(); @@ -16,7 +113,7 @@ class ManagerFile { .toList(); return fields; } - + // ----- Read a file FIT --- // Future> readFitFile(String path) async { if (File(path).existsSync() == false) return List.empty(); @@ -37,13 +134,7 @@ class ManagerFile { List readFitFileWeb(Uint8List bytes) { final fitFile = FitFile.fromBytes(bytes); return fitFile.toRows(); - } - - // ------------- Get The path of application --- // - Future get localPath async { - final directory = await getApplicationDocumentsDirectory(); - return directory.path; - } + }*/ /* // --- A modifier si utilisé --- // @@ -56,7 +147,7 @@ class ManagerFile { await outFile.writeAsString(await file.readAsString()); return true;*/ }*/ - + /* // -- Check si le fichier existe localement -- // Future fileExist(String filname) async { Directory directory = Directory("${await localPath}\\Files\\"); @@ -71,7 +162,7 @@ class ManagerFile { } } return false; - } + }*/ // --- Ligne utile --- // //final csv = const ListToCsvConverter().convert(fitFile.toRows()); diff --git a/lib/modele/utile/list_activity.dart/list_activity_utile.dart b/lib/modele/utile/list_activity.dart/list_activity_utile.dart index a5809c3..596a990 100644 --- a/lib/modele/utile/list_activity.dart/list_activity_utile.dart +++ b/lib/modele/utile/list_activity.dart/list_activity_utile.dart @@ -1,5 +1,4 @@ import 'dart:io'; - import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart'; @@ -13,9 +12,6 @@ class ListActivityUtile { final ManagerFile _managerFile = ManagerFile(); Future getContentOnTheFirstFileMobile(BuildContext context) async { - String fileUuid = - Provider.of(context, listen: false).listActivity[0].fileUuid; - Tuple2 result = await _strategy.getFile( Provider.of(context, listen: false).token, Provider.of(context, listen: false).listActivity[0].fileUuid); @@ -24,12 +20,16 @@ class ListActivityUtile { //print(result); return; } + /* File file = File( "${await _managerFile.localPath}/${Provider.of(context, listen: false).listActivity[0].nameFile}"); await file.create(); await file.writeAsBytes(result.item2); Provider.of(context, listen: false).listActivity[0].contentActivity = await _managerFile.readFitFileWhithFile(file); + */ + Provider.of(context, listen: false).listActivity[0].contentActivity = + _managerFile.convertByteIntoCSV(result.item2); } Future getContentOnTheFirstFileWeb(BuildContext context) async { @@ -42,6 +42,6 @@ class ListActivityUtile { return; } Provider.of(context, listen: false).listActivity[0].contentActivity = - await _managerFile.readFitFileWeb(result.item2); + _managerFile.convertByteIntoCSV(result.item2); } } diff --git a/lib/view/activity/mobile/mobile_list_activity.dart b/lib/view/activity/mobile/mobile_list_activity.dart index 936e531..fee5882 100644 --- a/lib/view/activity/mobile/mobile_list_activity.dart +++ b/lib/view/activity/mobile/mobile_list_activity.dart @@ -1,5 +1,8 @@ +import 'dart:convert'; import 'dart:io'; +import 'dart:typed_data'; +import 'package:csv/csv.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -7,6 +10,7 @@ import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/modele/activity.dart'; import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart'; import 'package:smartfit_app_mobile/modele/api/request_api.dart'; +import 'package:smartfit_app_mobile/modele/manager_file.dart'; import 'package:smartfit_app_mobile/modele/user.dart'; import 'package:smartfit_app_mobile/common_widget/container/workout_row.dart'; import 'package:smartfit_app_mobile/modele/utile/list_activity.dart/list_activity_utile.dart'; @@ -21,8 +25,9 @@ class MobileListActivity extends StatefulWidget { class _MobileListActivity extends State { FilePickerResult? result; - final IDataStrategy strategy = RequestApi(); + final IDataStrategy _strategy = RequestApi(); final ListActivityUtile _utile = ListActivityUtile(); + final ManagerFile _managerFile = ManagerFile(); int firstActivityIndex = 0; /* @@ -47,23 +52,42 @@ class _MobileListActivity extends State { } }*/ - void addFile(String path) async { + Future deleteFileOnBDD(String token, String fileUuid) async { + Tuple2 result = await _strategy.deleteFile(token, fileUuid); + if (!result.item1) { + print(fileUuid); + print("msg d'erreur"); + print(result.item2); + return false; + } + return true; + } + + void addFile(String path, String token, String filename) async { + // -- Transormer le fit en CSV + List> csv = _managerFile + .convertBytesFitFileIntoCSVList(await File(path).readAsBytes()); + String csvString = const ListToCsvConverter().convert(csv); + Uint8List byteCSV = Uint8List.fromList(utf8.encode(csvString)); // --- Save Local - // --- BDD - Tuple2 result = await strategy.uploadFile( - Provider.of(context, listen: false).token, File(path)); + // --- Api + String categoryActivity = filename.split("_").first.toLowerCase(); + String dateActivity = filename.split("_")[1].split("T").first; + + Tuple2 result = await _strategy.uploadFileByte( + token, byteCSV, filename, categoryActivity, dateActivity); + if (result.item1 == false) { // Afficher msg d'erreur print("Upload - ${result.item2}"); return; } - getFiles(); + getFiles(token); } - void getFiles() async { - Tuple2 result = await strategy - .getFiles(Provider.of(context, listen: false).token); + void getFiles(String token) async { + Tuple2 result = await _strategy.getFiles(token); if (result.item1 == false) { print("GetFiles - ${result.item2}"); // Afficher une message d'erreur @@ -107,7 +131,8 @@ class _MobileListActivity extends State { fontWeight: FontWeight.w700), ), TextButton( - onPressed: getFiles, + onPressed: () => getFiles( + Provider.of(context, listen: false).token), child: Text("Get activity", style: TextStyle( color: TColor.gray, @@ -118,7 +143,10 @@ class _MobileListActivity extends State { FilePickerResult? result = await FilePicker.platform.pickFiles(); if (result != null) { - addFile(result.files.single.path!); + addFile( + result.files.single.path!, + Provider.of(context, listen: false).token, + result.files.single.name); } else { print("Picker"); // msg d'erreur @@ -181,9 +209,14 @@ class _MobileListActivity extends State { }, child: WorkoutRow( wObj: activityMap, - onDelete: () { - Provider.of(context, listen: false) - .removeActivity(activityObj); + onDelete: () async { + if (await deleteFileOnBDD( + Provider.of(context, listen: false) + .token, + activityObj.fileUuid)) { + Provider.of(context, listen: false) + .removeActivity(activityObj); + } }, onClick: () { Provider.of(context, listen: false) diff --git a/lib/view/test/page_test.dart b/lib/view/test/page_test.dart index d4e677b..86aed19 100644 --- a/lib/view/test/page_test.dart +++ b/lib/view/test/page_test.dart @@ -268,8 +268,8 @@ class _TestPage extends State { print(await x.localPath); print("Save"); - print(await x - .readFitFile("${await x.localPath}/Walking_2023-11-08T10_57_28.fit")); + //print(await x + // .readFitFile("${await x.localPath}/Walking_2023-11-08T10_57_28.fit")); } Future getInfoUser() async { @@ -281,7 +281,7 @@ class _TestPage extends State { } void lunch() async { - print(await _managerFile.fileExist("lol")); + //print(await _managerFile.fileExist("lol")); } @override From 5cdd70de5b61e89a60def9c63f8741be6ecff0c9 Mon Sep 17 00:00:00 2001 From: Enzo Date: Mon, 27 Nov 2023 11:43:09 +0100 Subject: [PATCH 4/6] methode calcul csv --- Stub/compte.txt | 2 +- lib/common_widget/info.dart | 3 +- lib/common_widget/stats.dart | 3 +- lib/common_widget/steps.dart | 3 +- lib/modele/activity.dart | 260 ++++++++++++++++-- lib/modele/manager_file.dart | 13 +- .../utile/home_view/home_view_util.dart | 15 +- .../list_activity_utile.dart | 6 +- .../activity/mobile/mobile_list_activity.dart | 9 +- lib/view/activity/web/web_list_activity.dart | 31 ++- lib/view/home/mobile/mobile_homeview.dart | 2 +- 11 files changed, 297 insertions(+), 50 deletions(-) diff --git a/Stub/compte.txt b/Stub/compte.txt index d440232..485db0c 100644 --- a/Stub/compte.txt +++ b/Stub/compte.txt @@ -4,4 +4,4 @@ enzo@gmail.com toto toto@gmail.com -1234 \ No newline at end of file +toto \ No newline at end of file diff --git a/lib/common_widget/info.dart b/lib/common_widget/info.dart index c82720b..ac0ff16 100644 --- a/lib/common_widget/info.dart +++ b/lib/common_widget/info.dart @@ -9,7 +9,8 @@ class Info extends StatelessWidget { Widget build(BuildContext context) { String distance = Provider.of(context, listen: false) .listActivity[0] - .getTotalDistance(); + .getTotalDistance() + .toString(); return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, diff --git a/lib/common_widget/stats.dart b/lib/common_widget/stats.dart index 1591d68..013eb8f 100644 --- a/lib/common_widget/stats.dart +++ b/lib/common_widget/stats.dart @@ -17,7 +17,8 @@ class Stats extends StatelessWidget { .toString(); String time = Provider.of(context, listen: false) .listActivity[0] - .getTotalTime(); + .getTotalTime() + .toString(); return Column( children: [ diff --git a/lib/common_widget/steps.dart b/lib/common_widget/steps.dart index 5bee49f..db2370b 100644 --- a/lib/common_widget/steps.dart +++ b/lib/common_widget/steps.dart @@ -9,7 +9,8 @@ class Steps extends StatelessWidget { Widget build(BuildContext context) { String steps = Provider.of(context, listen: false) .listActivity[0] - .getTotalSteps(); + .getTotalSteps() + .toString(); return Padding( padding: const EdgeInsets.symmetric(vertical: 20), child: Column( diff --git a/lib/modele/activity.dart b/lib/modele/activity.dart index 58eb5cd..79d5bf8 100644 --- a/lib/modele/activity.dart +++ b/lib/modele/activity.dart @@ -11,15 +11,15 @@ class ActivityOfUser { late String _nameFile; // ------------ // late String _imageName; - late List> _contentActivity; + late List> _contentActivity; Map enteteCSV = {}; // ManagerFile for the field final ManagerFile _managerFile = ManagerFile(); // -- Getter/Setter -- // - List> get contentActivity => _contentActivity; - set contentActivity(List> content) { + List> get contentActivity => _contentActivity; + set contentActivity(List> content) { _contentActivity = content; for (int i = 0; i < content.first.length; i++) { enteteCSV.addAll({content.first[i]: i}); @@ -46,8 +46,41 @@ class ActivityOfUser { } } - // ----------------- BPM ------------------ // +// -- func utile -- // + bool notNull(int ligne, int colonne) { + if (_contentActivity[ligne][colonne] == "null") { + return false; + } + return true; + } + +// ----------------- X WithTime ------------ // + + List getXWithTime(String field) { + List result = List.empty(growable: true); + + int firstTimestamp = 0; + + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_$field"]!)) { + if (firstTimestamp == 0) { + firstTimestamp = contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!]; + } + result.add(FlSpot( + (((contentActivity[i][enteteCSV[ + "Value_${_managerFile.fieldTimeStamp}"]!]) - + firstTimestamp) ~/ + 100) + .toDouble(), + contentActivity[i][enteteCSV["Value_$field"]!].toDouble())); + } + } + return result; + } +// ----------------- BPM ------------------ // +/* // Retourne le Temps+BPM (Fichier CSV) List getHeartRateWithTime() { List result = List.empty(growable: true); @@ -70,7 +103,7 @@ class ActivityOfUser { [enteteCSV["Value_${_managerFile.fielBPM}"]!]))); } return result; - } + }*/ /* List getHeartRateWithTime() { @@ -101,16 +134,17 @@ class ActivityOfUser { // Retourne le BPM Max (Fichier CSV) int getMaxBpm() { - int max = int.parse( - contentActivity.first[enteteCSV["Value_${_managerFile.fielBPM}"]!]); - for (int i = 1; i < contentActivity.length; i++) { - int valueTmp = int.parse( - contentActivity[i][enteteCSV["Value_${_managerFile.fielBPM}"]!]); - if (valueTmp > max) { - max = valueTmp; + int max = 0; + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_${_managerFile.fielBPM}"]!)) { + int valueTmp = + contentActivity[i][enteteCSV["Value_${_managerFile.fielBPM}"]!]; + if (valueTmp > max) { + max = valueTmp; + } } } - return 0; + return max; } /* @@ -122,7 +156,22 @@ class ActivityOfUser { } return 0; }*/ +// Retourne le BPM Min (Fichier CSV) + int getMinBpm() { + int min = 300; + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_${_managerFile.fielBPM}"]!)) { + int valueTmp = + contentActivity[i][enteteCSV["Value_${_managerFile.fielBPM}"]!]; + if (valueTmp < min) { + min = valueTmp; + } + } + } + return min; + } + /* int getMinBpm() { for (int i = 0; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "min_heart_rate") { @@ -130,8 +179,22 @@ class ActivityOfUser { } } return 0; + }*/ + // Retourne le BPM avg (Fichier CSV) + int getAvgBpm() { + int somme = 0; + int nb = 0; + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_${_managerFile.fielBPM}"]!)) { + somme += contentActivity[i][enteteCSV["Value_${_managerFile.fielBPM}"]!] + as int; + nb++; + } + } + return somme ~/ nb; } + /* int getAvgBpm() { for (int i = 0; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "avg_heart_rate") { @@ -139,7 +202,7 @@ class ActivityOfUser { } } return 0; - } + }*/ // -------------------------- FIN BPM ---------------------- // /* // ---------------------- Distance ---------------------- // @@ -159,16 +222,23 @@ class ActivityOfUser { } return result; } - - String getTotalDistance() { - for (int i = 0; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "total_distance") { - return _contentActivity[_dataSession][i + 1].toString(); + */ + + double getTotalDistance() { + double max = 0; + for (int i = contentActivity.length - 1; i != 0; i--) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldDistance}"]!)) { + double valueTmp = contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldDistance}"]!]; + if (valueTmp > max) { + max = valueTmp; + } } } - return "null"; + return max; } + /* // ---------------------- FIN Distance ---------------------- // // ---------------------- Calories ---------------------- // @@ -188,8 +258,8 @@ class ActivityOfUser { } } return result; - } - + }*/ + /* String getTotalCalorie() { for (int i = 0; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "total_calories") { @@ -197,11 +267,16 @@ class ActivityOfUser { } } return "null"; + }*/ + + String getTotalCalorie() { + return "NULL"; } // ---------------------- FIN Calories ---------------------- // // ---------------------- Step ------------------------------// + /* String getTotalSteps() { for (int i = 0; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "total_strides") { @@ -209,10 +284,21 @@ class ActivityOfUser { } } return "null"; + }*/ + + int getTotalSteps() { + for (int i = contentActivity.length; i != 0; i--) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldTotalStep}"]!)) { + return contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldTotalStep}"]!]; + } + } + return 0; } // ----------------------- FIN Step ------------------------ // // ------------------------- Time ----------------------------- // + /* String getTotalTime() { for (int i = 0; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "total_elapsed_time") { @@ -220,10 +306,21 @@ class ActivityOfUser { } } return "null"; + }*/ + + int getTotalTime() { + for (int i = contentActivity.length - 1; i != 0; i--) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!)) { + return contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!]; + } + } + return 0; } // ---------------------------- FIN time -------------------- // // ---------------------------------------- Altitude -------------------- // + /* List getAltitudeWithTime() { List result = List.empty(growable: true); int firtTimeStamp = 0; @@ -239,8 +336,23 @@ class ActivityOfUser { } } return result; - } + }*/ + // --- Fichier CSV --- // + double getMaxAltitude() { + double max = 0; + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldAltitude}"]!)) { + double valueTmp = contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldAltitude}"]!]; + if (valueTmp > max) { + max = valueTmp; + } + } + } + return max; + } + /* double getMaxAltitude() { for (int i = 4; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "max_altitude") { @@ -248,8 +360,23 @@ class ActivityOfUser { } } return 0.0; - } + }*/ + // --- Fichier CSV --- // + double getMinAltitude() { + double min = 5000; + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldAltitude}"]!)) { + double valueTmp = contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldAltitude}"]!]; + if (valueTmp < min) { + min = valueTmp; + } + } + } + return min; + } + /* double getMinAltitude() { for (int i = 4; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "min_altitude") { @@ -257,7 +384,9 @@ class ActivityOfUser { } } return 0.0; - } + }*/ + + /* // -------------------------- FIN altitude ---------------------- // // -------------------------- Speed ---------------------- // @@ -283,8 +412,33 @@ class ActivityOfUser { } } return result; - } + }*/ + // -- CSV -- // + List getSpeedWithTimeActivity() { + List result = List.empty(growable: true); + int firstTimestamp = 0; + + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!) && + notNull(i, enteteCSV["Value_${_managerFile.fieldSpeed}"]!)) { + if (firstTimestamp == 0) { + firstTimestamp = contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!]; + } + result.add(DataPoint( + (((contentActivity[i][enteteCSV[ + "Value_${_managerFile.fieldTimeStamp}"]!]) - + firstTimestamp) ~/ + 100) + .toDouble(), + contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldSpeed}"]!])); + } + } + return result; + } + /* List getSpeedWithTimeActivity() { List result = List.empty(growable: true); int firtTimeStamp = 0; @@ -308,8 +462,23 @@ class ActivityOfUser { } } return result; - } + }*/ + // Retourne la Speed Max (Fichier CSV) + double getMaxSpeed() { + double max = 0.00; + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldSpeed}"]!)) { + double valueTmp = + contentActivity[i][enteteCSV["Value_${_managerFile.fieldSpeed}"]!]; + if (valueTmp > max) { + max = valueTmp; + } + } + } + return max; + } + /* double getMaxSpeed() { for (int i = 4; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "max_speed") { @@ -317,8 +486,22 @@ class ActivityOfUser { } } return 0.0; - } + }*/ + // Retourne avg Max (Fichier CSV) + double getAvgSpeed() { + double somme = 0; + int nb = 0; + for (int i = 0; i < contentActivity.length; i++) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldSpeed}"]!)) { + somme += + contentActivity[i][enteteCSV["Value_${_managerFile.fieldSpeed}"]!]; + nb++; + } + } + return somme / nb; + } + /* double getAvgSpeed() { for (int i = 4; i < _contentActivity[_dataSession].length; i++) { if (_contentActivity[_dataSession][i] == "avg_speed") { @@ -326,12 +509,31 @@ class ActivityOfUser { } } return 0.0; - } + }*/ // -------------------------- FIN Speed ---------------------- // // -------------------------- Localisation ------------------- // + // Retourne les positions (Fichier CSV) + List getPosition() { + List list = List.empty(growable: true); + + for (int i = 0; i < contentActivity.length; i++) { + if (notNull( + i, enteteCSV["Value_${_managerFile.fieldPositionLatitude}"]!) && + notNull( + i, enteteCSV["Value_${_managerFile.fieldPositionLongitude}"]!)) { + list.add(LatLng( + contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldPositionLatitude}"]!], + contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldPositionLongitude}"]!])); + } + } + return list; + } + /* List getPosition() { List list = List.empty(growable: true); diff --git a/lib/modele/manager_file.dart b/lib/modele/manager_file.dart index 1a58ee9..35aa968 100644 --- a/lib/modele/manager_file.dart +++ b/lib/modele/manager_file.dart @@ -11,12 +11,18 @@ class ManagerFile { final String _fieldPositionLongitude = "position_long"; final String _fieldDistance = "distance"; final String _fieldBPM = "heart_rate"; + final String _fieldSpeed = "speed"; + final String _fieldAltitude = "altitude"; + final String _fieldTotalStep = "total_strides"; // -- Getter field String get fieldTimeStamp => _fieldTimestamp; String get fieldPositionLatitude => _fieldPositionLatitue; String get fieldPositionLongitude => _fieldPositionLongitude; String get fieldDistance => _fieldDistance; String get fielBPM => _fieldBPM; + String get fieldSpeed => _fieldSpeed; + String get fieldAltitude => _fieldAltitude; + String get fieldTotalStep => _fieldTotalStep; List allowedFieldWalking = List.empty(growable: true); @@ -26,7 +32,10 @@ class ManagerFile { _fieldPositionLatitue, _fieldPositionLongitude, _fieldDistance, - _fieldBPM + _fieldBPM, + _fieldSpeed, + _fieldAltitude, + _fieldTotalStep ]; } @@ -92,7 +101,7 @@ class ManagerFile { } // -- Read the byte of file CSV -- // - List> convertByteIntoCSV(Uint8List bytes) { + List> convertByteIntoCSV(Uint8List bytes) { return const CsvToListConverter().convert(utf8.decode(bytes)); } diff --git a/lib/modele/utile/home_view/home_view_util.dart b/lib/modele/utile/home_view/home_view_util.dart index f6591d5..c909b31 100644 --- a/lib/modele/utile/home_view/home_view_util.dart +++ b/lib/modele/utile/home_view/home_view_util.dart @@ -2,16 +2,23 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smartfit_app_mobile/modele/activity.dart'; +import 'package:smartfit_app_mobile/modele/manager_file.dart'; import 'package:smartfit_app_mobile/modele/user.dart'; import 'package:smartfit_app_mobile/modele/utile/home_view/data_home_view.dart'; class HomeViewUtil { DataHomeView initData(BuildContext context) { - ActivityOfUser activity = Provider.of(context).listActivity[0]; + ManagerFile _managerFile = ManagerFile(); - List bpmSecondes = activity.getHeartRateWithTime(); - List vitesseSecondes = activity.getSpeedWithTime(); - List altitudeSeconde = activity.getAltitudeWithTime(); + ActivityOfUser activity = Provider.of(context).listActivity[0]; + //List bpmSecondes = activity.getHeartRateWithTime(); + List bpmSecondes = activity.getXWithTime(_managerFile.fielBPM); + //List vitesseSecondes = activity.getSpeedWithTime(); + List vitesseSecondes = + activity.getXWithTime(_managerFile.fieldSpeed); + //List altitudeSeconde = activity.getAltitudeWithTime(); + List altitudeSeconde = + activity.getXWithTime(_managerFile.fieldAltitude); List bpmSecondes2 = List.from(bpmSecondes); diff --git a/lib/modele/utile/list_activity.dart/list_activity_utile.dart b/lib/modele/utile/list_activity.dart/list_activity_utile.dart index 596a990..08c8faa 100644 --- a/lib/modele/utile/list_activity.dart/list_activity_utile.dart +++ b/lib/modele/utile/list_activity.dart/list_activity_utile.dart @@ -28,8 +28,9 @@ class ListActivityUtile { Provider.of(context, listen: false).listActivity[0].contentActivity = await _managerFile.readFitFileWhithFile(file); */ + Provider.of(context, listen: false).listActivity[0].contentActivity = - _managerFile.convertByteIntoCSV(result.item2); + List.from(_managerFile.convertByteIntoCSV(result.item2)); } Future getContentOnTheFirstFileWeb(BuildContext context) async { @@ -41,7 +42,8 @@ class ListActivityUtile { //print(result); return; } + /* Provider.of(context, listen: false).listActivity[0].contentActivity = - _managerFile.convertByteIntoCSV(result.item2); + _managerFile.convertByteIntoCSV(result.item2);*/ } } diff --git a/lib/view/activity/mobile/mobile_list_activity.dart b/lib/view/activity/mobile/mobile_list_activity.dart index fee5882..075ffd6 100644 --- a/lib/view/activity/mobile/mobile_list_activity.dart +++ b/lib/view/activity/mobile/mobile_list_activity.dart @@ -70,14 +70,12 @@ class _MobileListActivity extends State { String csvString = const ListToCsvConverter().convert(csv); Uint8List byteCSV = Uint8List.fromList(utf8.encode(csvString)); // --- Save Local - // --- Api String categoryActivity = filename.split("_").first.toLowerCase(); String dateActivity = filename.split("_")[1].split("T").first; Tuple2 result = await _strategy.uploadFileByte( token, byteCSV, filename, categoryActivity, dateActivity); - if (result.item1 == false) { // Afficher msg d'erreur print("Upload - ${result.item2}"); @@ -87,7 +85,9 @@ class _MobileListActivity extends State { } void getFiles(String token) async { + bool check = false; Tuple2 result = await _strategy.getFiles(token); + if (result.item1 == false) { print("GetFiles - ${result.item2}"); // Afficher une message d'erreur @@ -101,8 +101,11 @@ class _MobileListActivity extends State { element["category"].toString(), element["uuid"].toString(), element["filename"].toString())); + check = true; + } + if (check) { + await _utile.getContentOnTheFirstFileMobile(context); } - await _utile.getContentOnTheFirstFileMobile(context); return; } diff --git a/lib/view/activity/web/web_list_activity.dart b/lib/view/activity/web/web_list_activity.dart index 14731ff..3923c10 100644 --- a/lib/view/activity/web/web_list_activity.dart +++ b/lib/view/activity/web/web_list_activity.dart @@ -25,6 +25,8 @@ class _WebListActivityState extends State { IDataStrategy strategy = RequestApi(); final ListActivityUtile _utile = ListActivityUtile(); int firstActivityIndex = 0; + final IDataStrategy _strategy = RequestApi(); + /* void readFile(html.File file) async { ManagerFile x = ManagerFile(); @@ -44,6 +46,17 @@ class _WebListActivityState extends State { }); }*/ + Future deleteFileOnBDD(String token, String fileUuid) async { + Tuple2 result = await _strategy.deleteFile(token, fileUuid); + if (!result.item1) { + print(fileUuid); + print("msg d'erreur"); + print(result.item2); + return false; + } + return true; + } + void addFile(html.File file) async { final reader = html.FileReader(); reader.readAsArrayBuffer(file); @@ -74,6 +87,7 @@ class _WebListActivityState extends State { // -- On doit garder cet fonction dans la page pour pouvoir afficher les msg -- // void getFiles() async { + bool check = false; Tuple2 result = await strategy .getFiles(Provider.of(context, listen: false).token); if (result.item1 == false) { @@ -89,15 +103,17 @@ class _WebListActivityState extends State { element["category"].toString(), element["uuid"].toString(), element["filename"].toString())); + check = true; + } + if (check) { + await _utile.getContentOnTheFirstFileWeb(context); } - await _utile.getContentOnTheFirstFileWeb(context); return; } @override Widget build(BuildContext context) { var media = MediaQuery.of(context).size; - print("tttt"); return Scaffold( backgroundColor: TColor.white, body: SingleChildScrollView( @@ -194,9 +210,14 @@ class _WebListActivityState extends State { }, child: WorkoutRow( wObj: activityMap, - onDelete: () { - Provider.of(context, listen: false) - .removeActivity(activityObj); + onDelete: () async { + if (await deleteFileOnBDD( + Provider.of(context, listen: false) + .token, + activityObj.fileUuid)) { + Provider.of(context, listen: false) + .removeActivity(activityObj); + } }, onClick: () { Provider.of(context, listen: false) diff --git a/lib/view/home/mobile/mobile_homeview.dart b/lib/view/home/mobile/mobile_homeview.dart index b051c31..e5a79ab 100644 --- a/lib/view/home/mobile/mobile_homeview.dart +++ b/lib/view/home/mobile/mobile_homeview.dart @@ -28,6 +28,7 @@ class _MobileHomeView extends State { int maxBpm = context.watch().listActivity[0].getMaxBpm(); int minBpm = context.watch().listActivity[0].getMinBpm(); int avgBpm = context.watch().listActivity[0].getAvgBpm(); + // -- Altitude -- // double minAltitude = context.watch().listActivity[0].getMinAltitude(); double maxAltitude = context.watch().listActivity[0].getMaxAltitude(); @@ -35,7 +36,6 @@ class _MobileHomeView extends State { // -- Speed -- // double maxSpeed = context.watch().listActivity[0].getMaxSpeed(); double avgSpeed = context.watch().listActivity[0].getAvgSpeed(); - data = HomeViewUtil().initData(context); return Scaffold( From 35714bfbb7bffedb04da0c5d0d327902cf6eff24 Mon Sep 17 00:00:00 2001 From: Enzo Date: Mon, 27 Nov 2023 14:15:40 +0100 Subject: [PATCH 5/6] fonction data graph fini --- lib/common_widget/stats.dart | 30 ++-- lib/common_widget/steps.dart | 1 + lib/modele/activity.dart | 264 ++--------------------------------- lib/modele/manager_file.dart | 5 +- 4 files changed, 28 insertions(+), 272 deletions(-) diff --git a/lib/common_widget/stats.dart b/lib/common_widget/stats.dart index 013eb8f..ec551fa 100644 --- a/lib/common_widget/stats.dart +++ b/lib/common_widget/stats.dart @@ -10,7 +10,8 @@ class Stats extends StatelessWidget { Widget build(BuildContext context) { String calories = Provider.of(context, listen: false) .listActivity[0] - .getTotalCalorie(); + .getCalorie() + .toString(); String heartrate = Provider.of(context, listen: false) .listActivity[0] .getAvgBpm() @@ -19,7 +20,6 @@ class Stats extends StatelessWidget { .listActivity[0] .getTotalTime() .toString(); - return Column( children: [ Padding( @@ -33,7 +33,7 @@ class Stats extends StatelessWidget { fontWeight: FontWeight.w800, ), ), - SizedBox(width: 8), + const SizedBox(width: 8), Icon( Icons.pie_chart_rounded, size: 15, @@ -50,31 +50,31 @@ class Stats extends StatelessWidget { const SizedBox(width: 15), InfoStat( icon: Icons.timer, - iconColor: Color.fromARGB(255, 255, 255, 255), - iconBackground: Color(0xff6131AD), + iconColor: const Color.fromARGB(255, 255, 255, 255), + iconBackground: const Color(0xff6131AD), time: '+5s', label: 'Time', - value: time + ' s', + value: '$time s', ), - SizedBox(width: 15), + const SizedBox(width: 15), InfoStat( icon: Icons.favorite_outline, - iconColor: Color.fromARGB(255, 255, 255, 255), - iconBackground: Color(0xff6131AD), + iconColor: const Color.fromARGB(255, 255, 255, 255), + iconBackground: const Color(0xff6131AD), time: '+5s', label: 'Heart Rate', - value: heartrate + " BPM", + value: "$heartrate BPM", ), - SizedBox(width: 15), + const SizedBox(width: 15), InfoStat( icon: Icons.bolt, - iconColor: Color.fromARGB(255, 255, 255, 255), - iconBackground: Color(0xff6131AD), + iconColor: const Color.fromARGB(255, 255, 255, 255), + iconBackground: const Color(0xff6131AD), time: '+5s', label: 'Energy', - value: calories + " kCal", + value: "$calories kCal", ), - SizedBox(width: 30), + const SizedBox(width: 30), ], ), ) diff --git a/lib/common_widget/steps.dart b/lib/common_widget/steps.dart index db2370b..bbf770f 100644 --- a/lib/common_widget/steps.dart +++ b/lib/common_widget/steps.dart @@ -11,6 +11,7 @@ class Steps extends StatelessWidget { .listActivity[0] .getTotalSteps() .toString(); + return Padding( padding: const EdgeInsets.symmetric(vertical: 20), child: Column( diff --git a/lib/modele/activity.dart b/lib/modele/activity.dart index 79d5bf8..faf3f86 100644 --- a/lib/modele/activity.dart +++ b/lib/modele/activity.dart @@ -80,57 +80,6 @@ class ActivityOfUser { } // ----------------- BPM ------------------ // -/* -// Retourne le Temps+BPM (Fichier CSV) - List getHeartRateWithTime() { - List result = List.empty(growable: true); - int firstTimestamp = int.parse(contentActivity - .first[enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!]); - - result.add(FlSpot( - (firstTimestamp ~/ 100).toDouble(), - double.parse(contentActivity - .first[enteteCSV["Value_${_managerFile.fielBPM}"]!]))); - - for (int i = 1; i < contentActivity.length; i++) { - result.add(FlSpot( - ((int.parse(contentActivity[i][ - enteteCSV["Value_${_managerFile.fieldTimeStamp}"]!]) - - firstTimestamp) ~/ - 100) - .toDouble(), - double.parse(contentActivity[i] - [enteteCSV["Value_${_managerFile.fielBPM}"]!]))); - } - return result; - }*/ - - /* - List getHeartRateWithTime() { - List result = List.empty(growable: true); - int firtTimeStamp = 0; - - for (List ligne in _contentActivity) { - if (ligne[0] == "Data") { - if (ligne.length >= 10 && ligne[9] == "heart_rate") { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - //result.add([(ligne[4] - firtTimeStamp) ~/ 100, ligne[10]]); - result.add( - FlSpot((ligne[4] - firtTimeStamp) / 100, ligne[10].toDouble())); - } else if (ligne.length >= 16 && ligne[15] == "heart_rate") { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - //result.add([(ligne[4] - firtTimeStamp) ~/ 100, ligne[17]]); - result.add( - FlSpot((ligne[4] - firtTimeStamp) / 100, ligne[16].toDouble())); - } - } - } - return result; - }*/ // Retourne le BPM Max (Fichier CSV) int getMaxBpm() { @@ -147,15 +96,6 @@ class ActivityOfUser { return max; } - /* - int getMaxBpm() { - for (int i = 0; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "max_heart_rate") { - return _contentActivity[_dataSession][i + 1]; - } - } - return 0; - }*/ // Retourne le BPM Min (Fichier CSV) int getMinBpm() { int min = 300; @@ -171,15 +111,6 @@ class ActivityOfUser { return min; } - /* - int getMinBpm() { - for (int i = 0; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "min_heart_rate") { - return _contentActivity[_dataSession][i + 1]; - } - } - return 0; - }*/ // Retourne le BPM avg (Fichier CSV) int getAvgBpm() { int somme = 0; @@ -194,35 +125,9 @@ class ActivityOfUser { return somme ~/ nb; } - /* - int getAvgBpm() { - for (int i = 0; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "avg_heart_rate") { - return _contentActivity[_dataSession][i + 1]; - } - } - return 0; - }*/ // -------------------------- FIN BPM ---------------------- // - /* - // ---------------------- Distance ---------------------- // - List getDistanceWithTime() { - List result = List.empty(growable: true); - int firtTimeStamp = 0; - for (List ligne in _contentActivity) { - if (ligne.length >= 8 && ligne[0] == "Data" && ligne[6] == "distance") { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - //result.add([(ligne[4] - firtTimeStamp) ~/ 100, ligne[7].toInt()]); - result - .add(FlSpot((ligne[4] - firtTimeStamp) / 100, ligne[7].toDouble())); - } - } - return result; - } - */ + // ---------------------- Distance ---------------------- // double getTotalDistance() { double max = 0; @@ -238,56 +143,25 @@ class ActivityOfUser { return max; } - /* // ---------------------- FIN Distance ---------------------- // // ---------------------- Calories ---------------------- // - List getCalories() { - List result = List.empty(growable: true); - int firtTimeStamp = 0; - for (List ligne in _contentActivity) { - if (ligne.length >= 39 && - ligne[0] == "Data" && - ligne[39] == "total_calories") { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - //result.add([(ligne[4] - firtTimeStamp) ~/ 100, ligne[7].toInt()]); - result.add( - FlSpot((ligne[4] - firtTimeStamp) / 100, ligne[40].toDouble())); - } - } - return result; - }*/ - /* - String getTotalCalorie() { - for (int i = 0; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "total_calories") { - return _contentActivity[_dataSession][i + 1].toString(); + int getCalorie() { + for (int i = contentActivity.length - 1; i != 0; i--) { + if (notNull(i, enteteCSV["Value_${_managerFile.fieldTotalCalories}"]!)) { + return contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldTotalCalories}"]!] as int; } } - return "null"; - }*/ - - String getTotalCalorie() { - return "NULL"; + return 0; } // ---------------------- FIN Calories ---------------------- // // ---------------------- Step ------------------------------// - /* - String getTotalSteps() { - for (int i = 0; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "total_strides") { - return _contentActivity[_dataSession][i + 1].toString(); - } - } - return "null"; - }*/ int getTotalSteps() { - for (int i = contentActivity.length; i != 0; i--) { + for (int i = contentActivity.length - 1; i != 0; i--) { if (notNull(i, enteteCSV["Value_${_managerFile.fieldTotalStep}"]!)) { return contentActivity[i] [enteteCSV["Value_${_managerFile.fieldTotalStep}"]!]; @@ -298,15 +172,6 @@ class ActivityOfUser { // ----------------------- FIN Step ------------------------ // // ------------------------- Time ----------------------------- // - /* - String getTotalTime() { - for (int i = 0; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "total_elapsed_time") { - return _contentActivity[_dataSession][i + 1].toString(); - } - } - return "null"; - }*/ int getTotalTime() { for (int i = contentActivity.length - 1; i != 0; i--) { @@ -320,23 +185,6 @@ class ActivityOfUser { // ---------------------------- FIN time -------------------- // // ---------------------------------------- Altitude -------------------- // - /* - List getAltitudeWithTime() { - List result = List.empty(growable: true); - int firtTimeStamp = 0; - - for (List ligne in _contentActivity) { - if (ligne.length >= 14 && ligne[0] == "Data" && ligne[12] == "altitude") { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - //result.add([(ligne[4] - firtTimeStamp) ~/ 100, ligne[13].toInt()]); - result.add( - FlSpot((ligne[4] - firtTimeStamp) / 100, ligne[13].toDouble())); - } - } - return result; - }*/ // --- Fichier CSV --- // double getMaxAltitude() { @@ -352,15 +200,6 @@ class ActivityOfUser { } return max; } - /* - double getMaxAltitude() { - for (int i = 4; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "max_altitude") { - return _contentActivity[_dataSession][i + 1]; - } - } - return 0.0; - }*/ // --- Fichier CSV --- // double getMinAltitude() { @@ -376,44 +215,11 @@ class ActivityOfUser { } return min; } - /* - double getMinAltitude() { - for (int i = 4; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "min_altitude") { - return _contentActivity[_dataSession][i + 1]; - } - } - return 0.0; - }*/ - /* // -------------------------- FIN altitude ---------------------- // // -------------------------- Speed ---------------------- // - List getSpeedWithTime() { - List result = List.empty(growable: true); - int firtTimeStamp = 0; - - for (List ligne in _contentActivity) { - if (ligne[0] == "Data" && ligne[1] == 1) { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - result.add( - FlSpot((ligne[4] - firtTimeStamp) / 100, ligne[19].toDouble())); - } - if (ligne[0] == "Data" && ligne[1] == 2) { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - result.add( - FlSpot((ligne[4] - firtTimeStamp) / 100, ligne[25].toDouble())); - } - } - return result; - }*/ - // -- CSV -- // List getSpeedWithTimeActivity() { List result = List.empty(growable: true); @@ -438,31 +244,6 @@ class ActivityOfUser { } return result; } - /* - List getSpeedWithTimeActivity() { - List result = List.empty(growable: true); - int firtTimeStamp = 0; - - for (List ligne in _contentActivity) { - if (ligne[0] == "Data" && ligne[1] == 1) { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - result.add(DataPoint( - ((ligne[4] - firtTimeStamp) / 100), - ligne[19].toDouble(), - )); - } - if (ligne[0] == "Data" && ligne[1] == 2) { - if (firtTimeStamp == 0) { - firtTimeStamp = ligne[4]; - } - result.add(DataPoint( - ((ligne[4] - firtTimeStamp) / 100), ligne[25].toDouble())); - } - } - return result; - }*/ // Retourne la Speed Max (Fichier CSV) double getMaxSpeed() { @@ -478,15 +259,6 @@ class ActivityOfUser { } return max; } - /* - double getMaxSpeed() { - for (int i = 4; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "max_speed") { - return _contentActivity[_dataSession][i + 1]; - } - } - return 0.0; - }*/ // Retourne avg Max (Fichier CSV) double getAvgSpeed() { @@ -501,15 +273,6 @@ class ActivityOfUser { } return somme / nb; } - /* - double getAvgSpeed() { - for (int i = 4; i < _contentActivity[_dataSession].length; i++) { - if (_contentActivity[_dataSession][i] == "avg_speed") { - return _contentActivity[_dataSession][i + 1]; - } - } - return 0.0; - }*/ // -------------------------- FIN Speed ---------------------- // @@ -533,17 +296,6 @@ class ActivityOfUser { } return list; } - /* - List getPosition() { - List list = List.empty(growable: true); - - for (List ligne in _contentActivity) { - if (ligne[0] == "Data" && ligne[6] == "position_lat") { - list.add(LatLng(ligne[7], ligne[10])); - } - } - return list; - }*/ // -------------------------- FIN Localisation ---------------------- // diff --git a/lib/modele/manager_file.dart b/lib/modele/manager_file.dart index 35aa968..512c7e4 100644 --- a/lib/modele/manager_file.dart +++ b/lib/modele/manager_file.dart @@ -14,6 +14,7 @@ class ManagerFile { final String _fieldSpeed = "speed"; final String _fieldAltitude = "altitude"; final String _fieldTotalStep = "total_strides"; + final String _fieldTotalCalorie = "total_calories"; // -- Getter field String get fieldTimeStamp => _fieldTimestamp; String get fieldPositionLatitude => _fieldPositionLatitue; @@ -23,6 +24,7 @@ class ManagerFile { String get fieldSpeed => _fieldSpeed; String get fieldAltitude => _fieldAltitude; String get fieldTotalStep => _fieldTotalStep; + String get fieldTotalCalories => _fieldTotalCalorie; List allowedFieldWalking = List.empty(growable: true); @@ -35,7 +37,8 @@ class ManagerFile { _fieldBPM, _fieldSpeed, _fieldAltitude, - _fieldTotalStep + _fieldTotalStep, + _fieldTotalCalorie ]; } From eb1fa1e57d3ee12e1b81319f0a8b8c87108ca579 Mon Sep 17 00:00:00 2001 From: Enzo Date: Mon, 27 Nov 2023 16:00:05 +0100 Subject: [PATCH 6/6] gestion des fichier web et mobile fini --- lib/modele/activity.dart | 21 +++-- lib/modele/user.dart | 14 +--- .../list_activity_utile.dart | 49 ------------ .../list_activity/list_activity_utile.dart | 74 ++++++++++++++++++ .../activity/mobile/mobile_list_activity.dart | 61 ++++----------- lib/view/activity/web/web_list_activity.dart | 77 ++++++------------- 6 files changed, 128 insertions(+), 168 deletions(-) delete mode 100644 lib/modele/utile/list_activity.dart/list_activity_utile.dart create mode 100644 lib/modele/utile/list_activity/list_activity_utile.dart diff --git a/lib/modele/activity.dart b/lib/modele/activity.dart index faf3f86..7bb5e17 100644 --- a/lib/modele/activity.dart +++ b/lib/modele/activity.dart @@ -134,7 +134,8 @@ class ActivityOfUser { for (int i = contentActivity.length - 1; i != 0; i--) { if (notNull(i, enteteCSV["Value_${_managerFile.fieldDistance}"]!)) { double valueTmp = contentActivity[i] - [enteteCSV["Value_${_managerFile.fieldDistance}"]!]; + [enteteCSV["Value_${_managerFile.fieldDistance}"]!] + .toDouble(); if (valueTmp > max) { max = valueTmp; } @@ -164,7 +165,8 @@ class ActivityOfUser { for (int i = contentActivity.length - 1; i != 0; i--) { if (notNull(i, enteteCSV["Value_${_managerFile.fieldTotalStep}"]!)) { return contentActivity[i] - [enteteCSV["Value_${_managerFile.fieldTotalStep}"]!]; + [enteteCSV["Value_${_managerFile.fieldTotalStep}"]!] + .toInt(); } } return 0; @@ -192,7 +194,8 @@ class ActivityOfUser { for (int i = 0; i < contentActivity.length; i++) { if (notNull(i, enteteCSV["Value_${_managerFile.fieldAltitude}"]!)) { double valueTmp = contentActivity[i] - [enteteCSV["Value_${_managerFile.fieldAltitude}"]!]; + [enteteCSV["Value_${_managerFile.fieldAltitude}"]!] + .toDouble(); if (valueTmp > max) { max = valueTmp; } @@ -207,7 +210,8 @@ class ActivityOfUser { for (int i = 0; i < contentActivity.length; i++) { if (notNull(i, enteteCSV["Value_${_managerFile.fieldAltitude}"]!)) { double valueTmp = contentActivity[i] - [enteteCSV["Value_${_managerFile.fieldAltitude}"]!]; + [enteteCSV["Value_${_managerFile.fieldAltitude}"]!] + .toDouble(); if (valueTmp < min) { min = valueTmp; } @@ -238,8 +242,8 @@ class ActivityOfUser { firstTimestamp) ~/ 100) .toDouble(), - contentActivity[i] - [enteteCSV["Value_${_managerFile.fieldSpeed}"]!])); + contentActivity[i][enteteCSV["Value_${_managerFile.fieldSpeed}"]!] + .toDouble())); } } return result; @@ -250,8 +254,9 @@ class ActivityOfUser { double max = 0.00; for (int i = 0; i < contentActivity.length; i++) { if (notNull(i, enteteCSV["Value_${_managerFile.fieldSpeed}"]!)) { - double valueTmp = - contentActivity[i][enteteCSV["Value_${_managerFile.fieldSpeed}"]!]; + double valueTmp = contentActivity[i] + [enteteCSV["Value_${_managerFile.fieldSpeed}"]!] + .toDouble(); if (valueTmp > max) { max = valueTmp; } diff --git a/lib/modele/user.dart b/lib/modele/user.dart index c067711..ce294d8 100644 --- a/lib/modele/user.dart +++ b/lib/modele/user.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:smartfit_app_mobile/modele/activity.dart'; -import 'package:smartfit_app_mobile/modele/utile/list_activity.dart/list_activity_utile.dart'; +import 'package:smartfit_app_mobile/modele/utile/list_activity/list_activity_utile.dart'; class User extends ChangeNotifier { String username = "VOID"; @@ -23,16 +23,4 @@ class User extends ChangeNotifier { listActivity.insert(index, activity); notifyListeners(); } - - void insertActivityTopMobile(ActivityOfUser activity, BuildContext context) { - listActivity.insert(0, activity); - ListActivityUtile().getContentOnTheFirstFileMobile(context); - notifyListeners(); - } - - void insertActivityTopWeb(ActivityOfUser activity, BuildContext context) { - listActivity.insert(0, activity); - ListActivityUtile().getContentOnTheFirstFileWeb(context); - notifyListeners(); - } } diff --git a/lib/modele/utile/list_activity.dart/list_activity_utile.dart b/lib/modele/utile/list_activity.dart/list_activity_utile.dart deleted file mode 100644 index 08c8faa..0000000 --- a/lib/modele/utile/list_activity.dart/list_activity_utile.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'dart:io'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart'; -import 'package:smartfit_app_mobile/modele/api/request_api.dart'; -import 'package:smartfit_app_mobile/modele/manager_file.dart'; -import 'package:smartfit_app_mobile/modele/user.dart'; -import 'package:tuple/tuple.dart'; - -class ListActivityUtile { - final IDataStrategy _strategy = RequestApi(); - final ManagerFile _managerFile = ManagerFile(); - - Future getContentOnTheFirstFileMobile(BuildContext context) async { - Tuple2 result = await _strategy.getFile( - Provider.of(context, listen: false).token, - Provider.of(context, listen: false).listActivity[0].fileUuid); - if (result.item1 == false) { - //Erreur - //print(result); - return; - } - /* - File file = File( - "${await _managerFile.localPath}/${Provider.of(context, listen: false).listActivity[0].nameFile}"); - await file.create(); - await file.writeAsBytes(result.item2); - Provider.of(context, listen: false).listActivity[0].contentActivity = - await _managerFile.readFitFileWhithFile(file); - */ - - Provider.of(context, listen: false).listActivity[0].contentActivity = - List.from(_managerFile.convertByteIntoCSV(result.item2)); - } - - Future getContentOnTheFirstFileWeb(BuildContext context) async { - User user = Provider.of(context, listen: false); - Tuple2 result = - await _strategy.getFile(user.token, user.listActivity[0].fileUuid); - if (result.item1 == false) { - //Erreur - //print(result); - return; - } - /* - Provider.of(context, listen: false).listActivity[0].contentActivity = - _managerFile.convertByteIntoCSV(result.item2);*/ - } -} diff --git a/lib/modele/utile/list_activity/list_activity_utile.dart b/lib/modele/utile/list_activity/list_activity_utile.dart new file mode 100644 index 0000000..0ee8bae --- /dev/null +++ b/lib/modele/utile/list_activity/list_activity_utile.dart @@ -0,0 +1,74 @@ +import 'dart:convert'; +import 'dart:typed_data'; +import 'package:csv/csv.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:smartfit_app_mobile/modele/activity.dart'; +import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart'; +import 'package:smartfit_app_mobile/modele/api/request_api.dart'; +import 'package:smartfit_app_mobile/modele/manager_file.dart'; +import 'package:smartfit_app_mobile/modele/user.dart'; +import 'package:tuple/tuple.dart'; + +class ListActivityUtile { + final IDataStrategy _strategy = RequestApi(); + final ManagerFile _managerFile = ManagerFile(); + + Future> getContentActivity(BuildContext context) async { + Tuple2 result = await _strategy.getFile( + Provider.of(context, listen: false).token, + Provider.of(context, listen: false).listActivity[0].fileUuid); + if (result.item1 == false) { + return Tuple2(result.item1, result.item2); + } + Provider.of(context, listen: false).listActivity[0].contentActivity = + List.from(_managerFile.convertByteIntoCSV(result.item2)); + return const Tuple2(true, "Yeah"); + } + + Future> getFiles( + String token, BuildContext context) async { + bool notZero = false; + Tuple2 result = await _strategy + .getFiles(Provider.of(context, listen: false).token); + if (result.item1 == false) { + return Tuple2(result.item1, result.item2); + } + + for (Map element in result.item2) { + if (!notZero) { + Provider.of(context, listen: false).listActivity.clear(); + notZero = true; + } + Provider.of(context, listen: false).addActivity(ActivityOfUser( + element["creation_date"].toString(), + element["category"].toString(), + element["uuid"].toString(), + element["filename"].toString())); + } + + if (notZero) { + await getContentActivity(context); + } + return const Tuple2(true, "Yeah"); + } + + Future> addFile( + Uint8List bytes, String filename, String token) async { + // -- Transormer le fit en CSV + List> csv = _managerFile.convertBytesFitFileIntoCSVList(bytes); + String csvString = const ListToCsvConverter().convert(csv); + Uint8List byteCSV = Uint8List.fromList(utf8.encode(csvString)); + // --- Save Local + // --- Api + String categoryActivity = filename.split("_").first.toLowerCase(); + String dateActivity = filename.split("_")[1].split("T").first; + + Tuple2 result = await _strategy.uploadFileByte( + token, byteCSV, filename, categoryActivity, dateActivity); + if (result.item1 == false) { + return Tuple2(false, result.item2); + } + return const Tuple2(true, "Yeah"); + } +} diff --git a/lib/view/activity/mobile/mobile_list_activity.dart b/lib/view/activity/mobile/mobile_list_activity.dart index 075ffd6..3a978e7 100644 --- a/lib/view/activity/mobile/mobile_list_activity.dart +++ b/lib/view/activity/mobile/mobile_list_activity.dart @@ -13,7 +13,7 @@ import 'package:smartfit_app_mobile/modele/api/request_api.dart'; import 'package:smartfit_app_mobile/modele/manager_file.dart'; import 'package:smartfit_app_mobile/modele/user.dart'; import 'package:smartfit_app_mobile/common_widget/container/workout_row.dart'; -import 'package:smartfit_app_mobile/modele/utile/list_activity.dart/list_activity_utile.dart'; +import 'package:smartfit_app_mobile/modele/utile/list_activity/list_activity_utile.dart'; import 'package:tuple/tuple.dart'; class MobileListActivity extends StatefulWidget { @@ -63,50 +63,18 @@ class _MobileListActivity extends State { return true; } - void addFile(String path, String token, String filename) async { - // -- Transormer le fit en CSV - List> csv = _managerFile - .convertBytesFitFileIntoCSVList(await File(path).readAsBytes()); - String csvString = const ListToCsvConverter().convert(csv); - Uint8List byteCSV = Uint8List.fromList(utf8.encode(csvString)); - // --- Save Local - // --- Api - String categoryActivity = filename.split("_").first.toLowerCase(); - String dateActivity = filename.split("_")[1].split("T").first; - - Tuple2 result = await _strategy.uploadFileByte( - token, byteCSV, filename, categoryActivity, dateActivity); - if (result.item1 == false) { - // Afficher msg d'erreur - print("Upload - ${result.item2}"); + void addFileMobile(String path, String token, String filename) async { + Tuple2 resultAdd = + await _utile.addFile(await File(path).readAsBytes(), filename, token); + if (!resultAdd.item1) { + //print("Message error"); return; } - getFiles(token); - } - - void getFiles(String token) async { - bool check = false; - Tuple2 result = await _strategy.getFiles(token); - - if (result.item1 == false) { - print("GetFiles - ${result.item2}"); - // Afficher une message d'erreur + Tuple2 resultGet = await _utile.getFiles(token, context); + if (!resultGet.item1) { + //print("Message error"); return; } - Provider.of(context, listen: false).listActivity.clear(); - - for (Map element in result.item2) { - Provider.of(context, listen: false).addActivity(ActivityOfUser( - element["creation_date"].toString(), - element["category"].toString(), - element["uuid"].toString(), - element["filename"].toString())); - check = true; - } - if (check) { - await _utile.getContentOnTheFirstFileMobile(context); - } - return; } @override @@ -134,8 +102,9 @@ class _MobileListActivity extends State { fontWeight: FontWeight.w700), ), TextButton( - onPressed: () => getFiles( - Provider.of(context, listen: false).token), + onPressed: () => _utile.getFiles( + Provider.of(context, listen: false).token, + context), child: Text("Get activity", style: TextStyle( color: TColor.gray, @@ -146,7 +115,7 @@ class _MobileListActivity extends State { FilePickerResult? result = await FilePicker.platform.pickFiles(); if (result != null) { - addFile( + addFileMobile( result.files.single.path!, Provider.of(context, listen: false).token, result.files.single.name); @@ -225,8 +194,8 @@ class _MobileListActivity extends State { Provider.of(context, listen: false) .removeActivity(activityObj); Provider.of(context, listen: false) - .insertActivityTopMobile( - activityObj, context); + .insertActivity(0, activityObj); + _utile.getContentActivity(context); }, isFirstActivity: isFirstActivity, ), diff --git a/lib/view/activity/web/web_list_activity.dart b/lib/view/activity/web/web_list_activity.dart index 3923c10..8577f5a 100644 --- a/lib/view/activity/web/web_list_activity.dart +++ b/lib/view/activity/web/web_list_activity.dart @@ -1,6 +1,7 @@ +import 'dart:io'; import 'dart:typed_data'; import 'package:flutter/material.dart'; -import 'package:smartfit_app_mobile/modele/utile/list_activity.dart/list_activity_utile.dart'; +import 'package:smartfit_app_mobile/modele/utile/list_activity/list_activity_utile.dart'; import 'package:tuple/tuple.dart'; import 'package:universal_html/html.dart' as html; @@ -9,7 +10,6 @@ import 'package:provider/provider.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart'; import 'package:smartfit_app_mobile/modele/api/request_api.dart'; -import 'package:smartfit_app_mobile/modele/activity.dart'; import 'package:smartfit_app_mobile/modele/user.dart'; import 'package:smartfit_app_mobile/common_widget/container/workout_row.dart'; @@ -49,68 +49,36 @@ class _WebListActivityState extends State { Future deleteFileOnBDD(String token, String fileUuid) async { Tuple2 result = await _strategy.deleteFile(token, fileUuid); if (!result.item1) { - print(fileUuid); - print("msg d'erreur"); - print(result.item2); + //print(fileUuid); + //print("msg d'erreur"); + //print(result.item2); return false; } return true; } - void addFile(html.File file) async { + void addFileWeb(html.File file, String token) async { final reader = html.FileReader(); reader.readAsArrayBuffer(file); + reader.onLoadEnd.listen((event) async { if (reader.readyState == html.FileReader.DONE) { + print("donne"); Uint8List bytes = reader.result as Uint8List; - - String filename = file.name; - String categoryActivity = filename.split("_").first.toLowerCase(); - String dateActivity = filename.split("_")[1].split("T").first; - - Tuple2 result = await strategy.uploadFileByte( - Provider.of(context, listen: false).token, - bytes, - filename, - categoryActivity, - dateActivity); - - if (result.item1 == false) { - // Afficher msg d'erreur - print("Upload - ${result.item2}"); + Tuple2 resultAdd = + await _utile.addFile(bytes, file.name, token); + if (!resultAdd.item1) { + return; + } + Tuple2 resultGet = await _utile.getFiles(token, context); + if (!resultGet.item1) { + //print("MessageError"); return; } - getFiles(); } }); } - // -- On doit garder cet fonction dans la page pour pouvoir afficher les msg -- // - void getFiles() async { - bool check = false; - Tuple2 result = await strategy - .getFiles(Provider.of(context, listen: false).token); - if (result.item1 == false) { - print("GetFiles - ${result.item2}"); - // Afficher une message d'erreur - return; - } - Provider.of(context, listen: false).listActivity.clear(); - - for (Map element in result.item2) { - Provider.of(context, listen: false).addActivity(ActivityOfUser( - element["creation_date"].toString(), - element["category"].toString(), - element["uuid"].toString(), - element["filename"].toString())); - check = true; - } - if (check) { - await _utile.getContentOnTheFirstFileWeb(context); - } - return; - } - @override Widget build(BuildContext context) { var media = MediaQuery.of(context).size; @@ -135,7 +103,9 @@ class _WebListActivityState extends State { fontWeight: FontWeight.w700), ), TextButton( - onPressed: getFiles, + onPressed: () => _utile.getFiles( + Provider.of(context, listen: false).token, + context), child: Text("Get activity", style: TextStyle( color: TColor.gray, @@ -150,7 +120,10 @@ class _WebListActivityState extends State { uploadInput.onChange.listen((e) { final files = uploadInput.files; if (files != null && files.isNotEmpty) { - addFile(files[0]); // Lecture du fichier sélectionné + addFileWeb( + files[0], + Provider.of(context, listen: false) + .token); // Lecture du fichier sélectionné } }); }, @@ -223,8 +196,8 @@ class _WebListActivityState extends State { Provider.of(context, listen: false) .removeActivity(activityObj); Provider.of(context, listen: false) - .insertActivityTopWeb( - activityObj, context); + .insertActivity(0, activityObj); + _utile.getContentActivity(context); }, isFirstActivity: isFirstActivity, ),