From 665a33cb63ab8c5ce1b81e07f81d59b8ba316214 Mon Sep 17 00:00:00 2001 From: Dorian HODIN Date: Thu, 17 Nov 2022 11:00:34 +0100 Subject: [PATCH] Function now in user.dart --- .idea/libraries/Dart_Packages.xml | 328 +++++++++--------- .../dafl_project_flutter/lib/model/user.dart | 47 ++- .../lib/position/location.dart | 21 +- .../lib/views/pages/main/p_main.dart | 15 +- 4 files changed, 214 insertions(+), 197 deletions(-) diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index 0568fe9..9c93a4a 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -5,662 +5,662 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/dafl_project_flutter/lib/model/user.dart b/Sources/dafl_project_flutter/lib/model/user.dart index 9a47fbf..b79c2e6 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -1,10 +1,15 @@ -import '../api/track.dart'; +import 'dart:async'; +import '../../../api/track.dart'; +import '../../../position/location.dart'; import '../exceptions/api_exception.dart'; import '../main.dart'; import 'conversation.dart'; import 'music.dart'; import 'spot.dart'; +Timer? timer; +int test=0; + class User { //attributes from DAFL late int idDafl; @@ -72,6 +77,46 @@ class User { } } + static List listspots (){ + Future? rep; + List tracklist = []; + int i=0; + String listOfTrack=""; + rep = Location.sendCurrentLocation(); + List> futuretracklist = []; + List> trackid = []; + rep.then((String result) { + listOfTrack = result; + List tab = result.split(","); + for (i = 0; i < tab.length; i++) { + trackid.add(tab[i].split("-")); + } + for (i = 0; i < trackid.length; i++) { + futuretracklist.add(MyApp.api.getTrackInfo(trackid[i][1])); + } + for (i = 0; i < futuretracklist.length; i++) { + futuretracklist[i].then((Track t) { + tracklist.add(t); + if (i + 1 == futuretracklist.length) { + return tracklist; + } + }); + } + }); + return []; + } + + static List getListSpots(){ + List listTrack =[]; + if (test==0){ + test=1; + listTrack = listspots(); + }else{ + timer = Timer.periodic(const Duration(seconds: 10), (Timer t) => listTrack=listspots()); + } + return listTrack; + } + @override String toString() => "$usernameDafl ($passwDafl)"; } diff --git a/Sources/dafl_project_flutter/lib/position/location.dart b/Sources/dafl_project_flutter/lib/position/location.dart index cda3f07..73e937c 100644 --- a/Sources/dafl_project_flutter/lib/position/location.dart +++ b/Sources/dafl_project_flutter/lib/position/location.dart @@ -1,6 +1,3 @@ -import 'dart:developer'; -import '../api/api.dart'; -import 'package:dafl_project_flutter/api/track.dart'; import 'package:geolocator/geolocator.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; @@ -43,23 +40,7 @@ class Location { return data.toString(); } - static List> getTrackList(Future userList){ - int i=0; - String listOfTrack=""; - List> tracklist = []; - List> trackid = []; - userList.then((String result) { - listOfTrack = result; - List tab = result.split(","); - for (i=0; i < tab.length; i++){ - trackid.add(tab[i].split("-")); - } - for (i=0; i < trackid.length; i++){ - tracklist.add(MyApp.api.getTrackInfo(trackid[i][1])); - } - }); - return tracklist; - } + } diff --git a/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart b/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart index 4bf11ea..b336882 100644 --- a/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart +++ b/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart @@ -1,7 +1,5 @@ -import 'dart:async'; import 'package:flutter/material.dart'; import '../../../api/track.dart'; -import '../../../position/location.dart'; import '../../../presentation/custom_icons_icons.dart'; import './w_settings.dart'; import './w_spot.dart'; @@ -9,8 +7,8 @@ import './w_discovery.dart'; import './w_profile.dart'; import './w_messages.dart'; import 'w_top.dart'; -Timer? timer; -int test=0; +import '../../../model/user.dart'; + class MainPage extends StatefulWidget { @@ -35,14 +33,7 @@ class _MainPageState extends State { @override Widget build(BuildContext context) { - Future? rep; - if (test==0){ - rep = Location.sendCurrentLocation(); - //List tracklist = Location.getTrackList(rep); - Location.getTrackList(rep); - test=0; - } - timer = Timer.periodic(const Duration(seconds: 10), (Timer t) => rep = Location.sendCurrentLocation()); + List spots = User.getListSpots(); double height = MediaQuery.of(context).size.height; return Scaffold( resizeToAvoidBottomInset: false,