From 338f6381cbb78d815e4d66124415899d8f06bff9 Mon Sep 17 00:00:00 2001 From: Dorian HODIN Date: Wed, 30 Nov 2022 12:56:09 +0100 Subject: [PATCH] setSpots now in controller.dart --- .idea/libraries/Dart_Packages.xml | 96 +++++++++++++++++++ .../lib/controller/controller.dart | 43 +++++---- .../lib/views/pages/main/p_main.dart | 9 -- 3 files changed, 121 insertions(+), 27 deletions(-) diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index fc497d8..5b21219 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -2,6 +2,20 @@ + + @@ -639,14 +725,19 @@ + + + + + @@ -661,6 +752,7 @@ + @@ -678,6 +770,7 @@ + @@ -693,6 +786,7 @@ + @@ -704,10 +798,12 @@ + + diff --git a/Sources/dafl_project_flutter/lib/controller/controller.dart b/Sources/dafl_project_flutter/lib/controller/controller.dart index 6ba0afc..737a02d 100644 --- a/Sources/dafl_project_flutter/lib/controller/controller.dart +++ b/Sources/dafl_project_flutter/lib/controller/controller.dart @@ -1,4 +1,4 @@ -import 'dart:collection'; +import 'dart:async'; import 'dart:convert'; import 'package:dafl_project_flutter/controller/live_datas.dart'; import 'package:dafl_project_flutter/model/music.dart'; @@ -11,48 +11,55 @@ import 'package:http/http.dart' as http; import '../model/user.dart'; class Controller { - final ApiSpotify _api = ApiSpotify(); + ApiSpotify _api = ApiSpotify(); late User _currentUser; final DataBaseService _dataBaseService = DataBaseService(); - final LiveData _data = LiveData(); + final LiveDatas _datas = LiveDatas(); late BuildContext navigatorKey; + // + // Constructor + // + + Controller(){ + setSpots(); + Timer.periodic(const Duration(seconds: 10), (Timer t) => setSpots()); + } // - // Methods to manage data + // Methods to manage datas // - // Data that can change + // Datas that can change - bool getChoice() => _data.discoveriesSortChoice; + bool getChoice() => _datas.discoveriesSortChoice; setChoice(bool c) { - _data.discoveriesSortChoice = c; + _datas.discoveriesSortChoice = c; } - Music getCurrentMusic() => _data.userCurrentMusic; + Music getCurrentMusic() => _datas.userCurrentMusic; setCurrentMusic() async { - _data.userCurrentMusic = + _datas.userCurrentMusic = await getCompleteMusic(await _api.requests.getCurrentlyPlayingTrack()); } - List getSpots() => _data.spots; + List getSpots() => _datas.spots; setSpots() async { - _data.spots = await Location.sendCurrentLocation(); + _datas.spots = await Location.sendCurrentLocation(); } - LinkedHashMap getDiscoveries() => _data.discoveries; + Map getDiscoveries() => _datas.discoveries; setDiscoveries() async { - LinkedHashMap tmpData = - await _api.requests.getPlaylistTracks(); - LinkedHashMap tmpCast = LinkedHashMap(); + Map tmpData = await _api.requests.getPlaylistTracks(); + Map tmpCast = {}; tmpData.forEach((key, value) async { tmpCast[(await getCompleteMusic(key))] = value; }); - _data.discoveries = tmpCast; + _datas.discoveries = tmpCast; } //Data that can not change @@ -74,8 +81,8 @@ class Controller { } Future getCompleteMusic(String id) async { - Map info = await _api.requests.getTrackInfo(id); - return Music(id, info['name'], info['artist'], info['cover']); + Map infos = await _api.requests.getTrackInfo(id); + return Music(id, infos['name'], infos['artist'], infos['cover']); } removeFromPlaylist(String id) { 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 0f7d518..4b3d579 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,5 +1,3 @@ -import 'dart:async'; -import 'package:dafl_project_flutter/main.dart'; import 'package:flutter/material.dart'; import '../../presentation/custom_icons_icons.dart'; import './w_settings.dart'; @@ -108,13 +106,6 @@ class _MainPageState extends State { ), ); } - - @override - void initState() { - super.initState(); - Timer timer = Timer.periodic( - const Duration(seconds: 10), (Timer t) => MyApp.controller.getSpots()); - } } class GradientText extends StatelessWidget {