button to sort list
continuous-integration/drone/push Build is passing Details

messagerie_lucas_test
Lucas DELANIER 2 years ago
parent be008d42e7
commit 38f2b742a5

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

@ -223,6 +223,7 @@ class CardProvider extends ChangeNotifier {
); );
if (!MyApp.controller.currentUser.discovery if (!MyApp.controller.currentUser.discovery
.contains(MyApp.controller.currentUser.spots.last.music)) { .contains(MyApp.controller.currentUser.spots.last.music)) {
MyApp.controller.currentUser.spots.last.music.defineDate();
MyApp.controller.currentUser MyApp.controller.currentUser
.addDiscovery(MyApp.controller.currentUser.spots.last.music); .addDiscovery(MyApp.controller.currentUser.spots.last.music);
notifyListeners(); notifyListeners();

@ -1,11 +1,11 @@
class Music{ class Music {
String name; String name;
String artist; String artist;
String linkCover; String linkCover;
late DateTime date;
Music(this.name, this.artist, this.linkCover); Music(this.name, this.artist, this.linkCover);
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
identical(this, other) || identical(this, other) ||
@ -16,4 +16,8 @@ class Music{
@override @override
int get hashCode => name.hashCode ^ artist.hashCode; int get hashCode => name.hashCode ^ artist.hashCode;
void defineDate() {
this.date = new DateTime.now();
}
} }

@ -8,7 +8,7 @@ import 'music.dart';
import 'spot.dart'; import 'spot.dart';
Timer? timer; Timer? timer;
int test=0; int test = 0;
class User { class User {
//attributes from DAFL //attributes from DAFL
@ -19,6 +19,7 @@ class User {
//attributes with Spotify API //attributes with Spotify API
late String _id; late String _id;
late Track track; late Track track;
bool sortChoise = true;
//constructors //constructors
User(this.usernameDafl, this.passwDafl) { User(this.usernameDafl, this.passwDafl) {
@ -73,7 +74,7 @@ class User {
} }
} }
void listspots (){ void listspots() {
Future<String>? rep; Future<String>? rep;
int i; int i;
rep = Location.sendCurrentLocation(); rep = Location.sendCurrentLocation();
@ -81,7 +82,7 @@ class User {
List<List<String>> musicId = []; List<List<String>> musicId = [];
rep.then((String result) { rep.then((String result) {
List<String> tab = result.split(","); List<String> tab = result.split(",");
if (tab.isEmpty!=true) { if (tab.isEmpty != true) {
for (i = 0; i < tab.length; i++) { for (i = 0; i < tab.length; i++) {
musicId.add(tab[i].split("-")); musicId.add(tab[i].split("-"));
} }
@ -97,15 +98,16 @@ class User {
*/ // EN COMMENTAIRE PARCE QUE ERREUR SINON VU QUE J'AI PAS MUSIC POUR L'INSTANT */ // EN COMMENTAIRE PARCE QUE ERREUR SINON VU QUE J'AI PAS MUSIC POUR L'INSTANT
} }
}); });
} }
void getListSpots(){ void getListSpots() {
if (test==0){ if (test == 0) {
test=1; test = 1;
listspots(); listspots();
}else{ } else {
timer = Timer.periodic(const Duration(seconds: 72), (Timer t) => listspots()); timer =
Timer.periodic(const Duration(seconds: 72), (Timer t) => listspots());
} }
} }

@ -2,6 +2,8 @@ import 'package:dafl_project_flutter/main.dart';
import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../model/music.dart';
class DiscoveryWidget extends StatefulWidget { class DiscoveryWidget extends StatefulWidget {
const DiscoveryWidget({Key? key}) : super(key: key); const DiscoveryWidget({Key? key}) : super(key: key);
@ -20,25 +22,42 @@ class _DiscoveryWidgetState extends State<DiscoveryWidget> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Container(
padding: const EdgeInsets.fromLTRB(30, 0, 30, 0), padding: const EdgeInsets.fromLTRB(30, 0, 10, 0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row(children: const [ Row(
Text( mainAxisAlignment: MainAxisAlignment.spaceBetween,
'Playlist découverte', children: [
style: TextStyle( Text(
color: Colors.white, 'Playlist découverte',
fontWeight: FontWeight.w500, style: TextStyle(
fontSize: 25), color: Colors.white,
), fontWeight: FontWeight.w500,
Spacer(), fontSize: 25),
Icon( ),
FontAwesome5.sort_amount_down, OutlinedButton(
size: 30, onPressed: () {
color: Colors.white, MyApp.controller.currentUser.sortChoise =
), !MyApp.controller.currentUser.sortChoise;
]), setState(() {});
},
style: OutlinedButton.styleFrom(
shadowColor: Colors.black,
shape: CircleBorder(),
padding: EdgeInsets.all(24),
primary: Colors.grey),
child: MyApp.controller.currentUser.sortChoise
? Image.asset(
'assets/images/date_sort_icon.png',
height: 25,
)
: Image.asset(
'assets/images/alpha_sort_icon.png',
height: 25,
),
),
]),
const Padding(padding: EdgeInsets.fromLTRB(0, 5, 0, 0)), const Padding(padding: EdgeInsets.fromLTRB(0, 5, 0, 0)),
Text( Text(
'Retrouvez ici vos nouvelles découvertes.', 'Retrouvez ici vos nouvelles découvertes.',
@ -83,38 +102,46 @@ class _DiscoveryListState extends State<DiscoveryList> {
refreshList() async { refreshList() async {
await Future.delayed(const Duration(seconds: 1)); await Future.delayed(const Duration(seconds: 1));
setState(() { setState(() {});
MyApp.controller.currentUser.discovery;
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
List<Music> listDiscovery = MyApp.controller.currentUser.discovery;
if (MyApp.controller.currentUser.sortChoise) {
listDiscovery.sort((a, b) {
return a.date.compareTo(b.date);
});
} else {
listDiscovery.sort((a, b) {
return a.name.compareTo(b.name);
});
}
return RefreshIndicator( return RefreshIndicator(
onRefresh: () async { onRefresh: () async {
refreshList(); refreshList();
setState(() {});
}, },
key: refreshKey, key: refreshKey,
child: ListView.builder( child: ListView.builder(
itemCount: MyApp.controller.currentUser.discovery.length, itemCount: listDiscovery.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
int itemCount = MyApp.controller.currentUser.discovery.length; int itemCount = listDiscovery.length;
int reversedIndex = itemCount - 1 - index; int reversedIndex = itemCount - 1 - index;
return Dismissible( return Dismissible(
key: Key(MyApp movementDuration: Duration(milliseconds: 400),
.controller.currentUser.discovery[reversedIndex].name), key: Key(listDiscovery[index].name),
confirmDismiss: (direction) async { confirmDismiss: (direction) async {
if (direction == DismissDirection.endToStart) { if (direction == DismissDirection.endToStart) {
print(listDiscovery[reversedIndex].name);
MyApp.controller.currentUser.discovery MyApp.controller.currentUser.discovery
.removeAt(reversedIndex); .remove(listDiscovery[reversedIndex]);
setState(() { setState(() {});
itemCount -= 1;
});
return true;
} }
}, },
onDismissed: (direction) { onDismissed: (direction) {
if (direction == DismissDirection.startToEnd) { if (direction == DismissDirection.startToEnd) {
print(listDiscovery[reversedIndex].name);
print('play'); print('play');
} }
}, },
@ -184,7 +211,7 @@ class _DiscoveryListState extends State<DiscoveryList> {
color: Colors.white color: Colors.white
.withOpacity(0.6), .withOpacity(0.6),
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w400)) fontWeight: FontWeight.w400)),
])) ]))
])) ]))
]))); ])));

Loading…
Cancel
Save