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();

@ -2,10 +2,10 @@ 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();
}
} }

@ -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) {
@ -105,7 +106,8 @@ class User {
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,11 +22,13 @@ 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(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text( Text(
'Playlist découverte', 'Playlist découverte',
style: TextStyle( style: TextStyle(
@ -32,11 +36,26 @@ class _DiscoveryWidgetState extends State<DiscoveryWidget> {
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontSize: 25), fontSize: 25),
), ),
Spacer(), OutlinedButton(
Icon( onPressed: () {
FontAwesome5.sort_amount_down, MyApp.controller.currentUser.sortChoise =
size: 30, !MyApp.controller.currentUser.sortChoise;
color: Colors.white, 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)),
@ -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