Merge remote-tracking branch 'origin/sort_items_discovery'

# Conflicts:
#	.idea/libraries/Dart_Packages.xml
#	.idea/libraries/Dart_SDK.xml
#	Sources/dafl_project_flutter/lib/model/music.dart
#	Sources/dafl_project_flutter/lib/model/user.dart
#	Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart
messagerie_lucas_test
Lucas Delanier 2 years ago
commit 822f90f58c

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

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

@ -6,6 +6,7 @@ class Music {
late String _artist;
late String _linkCover;
final String _id;
late DateTime date;
Music(this._id) {
_completeInfo();
@ -26,4 +27,18 @@ class Music {
// TODO : add notification to show that an error occured
}
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Music &&
runtimeType == other.runtimeType &&
name == other.name &&
artist == other.artist;
@override
int get hashCode => name.hashCode ^ artist.hashCode;
void defineDate() {
this.date = new DateTime.now();
}
}

@ -19,6 +19,7 @@ class User {
//attributes with Spotify API
String? _idSpotify; //use _getIdUser() as kind of a private getter
late Music _currentMusic;
bool sortChoise = true;
//constructors
User(this.usernameDafl, this.passwDafl) {

@ -3,6 +3,8 @@ import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:flutter/material.dart';
import 'dart:developer' as dev;
import '../../../model/music.dart';
class DiscoveryWidget extends StatefulWidget {
const DiscoveryWidget({Key? key}) : super(key: key);
@ -21,11 +23,13 @@ class _DiscoveryWidgetState extends State<DiscoveryWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.fromLTRB(30, 0, 30, 0),
padding: const EdgeInsets.fromLTRB(30, 0, 10, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: const [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Playlist découverte',
style: TextStyle(
@ -33,11 +37,29 @@ class _DiscoveryWidgetState extends State<DiscoveryWidget> {
fontWeight: FontWeight.w500,
fontSize: 25),
),
Spacer(),
Icon(
FontAwesome5.sort_amount_down,
size: 30,
color: Colors.white,
OutlinedButton(
onPressed: () {
MyApp.controller.currentUser.sortChoise =
!MyApp.controller.currentUser.sortChoise;
rebuildAllChildren(context);
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)),
@ -63,6 +85,13 @@ class _DiscoveryWidgetState extends State<DiscoveryWidget> {
),
);
}
void rebuildAllChildren(BuildContext context) {
void rebuild(Element el) {
el.markNeedsBuild();
el.visitChildren(rebuild);
}
(context as Element).visitChildren(rebuild);
}
}
class DiscoveryList extends StatefulWidget {
@ -84,39 +113,47 @@ class _DiscoveryListState extends State<DiscoveryList> {
refreshList() async {
await Future.delayed(const Duration(seconds: 1));
setState(() {
MyApp.controller.currentUser.discovery;
});
setState(() {});
}
@override
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(
onRefresh: () async {
refreshList();
setState(() {});
},
key: refreshKey,
child: ListView.builder(
itemCount: MyApp.controller.currentUser.discovery.length,
itemCount: listDiscovery.length,
itemBuilder: (context, index) {
int itemCount = MyApp.controller.currentUser.discovery.length;
int itemCount = listDiscovery.length;
int reversedIndex = itemCount - 1 - index;
return Dismissible(
key: Key(MyApp
.controller.currentUser.discovery[reversedIndex].name),
movementDuration: Duration(milliseconds: 400),
key: Key(listDiscovery[index].name),
confirmDismiss: (direction) async {
if (direction == DismissDirection.endToStart) {
print(listDiscovery[reversedIndex].name);
MyApp.controller.currentUser.discovery
.removeAt(reversedIndex);
setState(() {
itemCount -= 1;
});
return true;
.remove(listDiscovery[reversedIndex]);
setState(() {});
}
},
onDismissed: (direction) {
if (direction == DismissDirection.startToEnd) {
dev.log('play');
print(listDiscovery[reversedIndex].name);
print('play');
}
},
background: Container(
@ -185,7 +222,7 @@ class _DiscoveryListState extends State<DiscoveryList> {
color: Colors.white
.withOpacity(0.6),
fontSize: 16,
fontWeight: FontWeight.w400))
fontWeight: FontWeight.w400)),
]))
]))
])));

Loading…
Cancel
Save