Résolution d'erreurs

remotes/origin/database-api-implementation
Félix MIELCAREK 2 years ago committed by felixmielcarek
parent 7b3b514770
commit e049a265cd

@ -2,7 +2,7 @@ import 'dart:convert';
import 'package:dafl_project_flutter/model/music.dart';
import 'package:dafl_project_flutter/services/api/api_spotify.dart';
import 'package:dafl_project_flutter/services/database/database_service.dart';
import 'package:dafl_project_flutter/services/position/area.dart';
import 'package:dafl_project_flutter/services/position/location.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import '../model/spot.dart';
@ -11,8 +11,9 @@ import '../model/user.dart';
class Controller {
ApiSpotify _api = ApiSpotify();
late User _currentUser;
Area _area = Area();
DataBaseService _dataBaseService = DataBaseService();
final Location _location = Location();
final DataBaseService _dataBaseService = DataBaseService();
bool sortChoice = false; //false = sort by name ; true = sort by date
late BuildContext navigatorKey;
@ -50,13 +51,11 @@ class Controller {
}
List<Spot> getSpots() {
return _area.spots;
return _location.spots;
}
Future<List<Spot>> getArea() async {
await _area.sendCurrentLocation();
await _area.getData();
return _area.spots;
getLocation() async {
await _location.sendCurrentLocation();
}
playTrack(String id) {
@ -76,7 +75,6 @@ class Controller {
_api.requests.addToPlaylist(id);
}
// DATABASE
void save(User userToSave) {
_dataBaseService.save(userToSave);
@ -98,12 +96,8 @@ class Controller {
return await _dataBaseService.searchUser(username);
}
Future sendEmail(
User reporter, User reported, String reason, String message) async {
Future sendEmail(String reporterId, String reportedId, String reason,
String message) async {
const serviceId = 'service_dzyndyb';
const templateId = 'template_idgriw2';
const userId = 'hy7HxL5QGV6gpdqry';
@ -119,13 +113,12 @@ class Controller {
'template_id': templateId,
'user_id': userId,
'template_params': {
'from_name': reporter.usernameDafl,
'to_name': reported.usernameDafl,
'from_name': reporterId,
'to_name': reportedId,
'reason': reason,
'message': message,
},
}),
);
}
*/
}

@ -46,14 +46,11 @@ class MyApp extends StatelessWidget {
enum CardStatus { like, disLike, discovery, message }
class CardProvider extends ChangeNotifier {
final List<Spot> _spotsList = MyApp.controller.getSpots();
bool _isDragging = false;
double _angle = 0;
Offset _position = Offset.zero;
Size _screenSize = Size.zero;
List<Spot> get spotsList => _spotsList;
bool get isDragging => _isDragging;
Offset get position => _position;
@ -373,14 +370,15 @@ class CardProvider extends ChangeNotifier {
}
Future _nextCard() async {
dev.log(_spotsList.length.toString());
if (_spotsList.isEmpty) {
List<Spot> spots = MyApp.controller.getSpots();
dev.log(spots.length.toString());
if (spots.isEmpty) {
dev.log('dernier');
return;
} else {
await Future.delayed(const Duration(milliseconds: 200));
dev.log(_spotsList.last.music.name);
_spotsList.removeLast();
dev.log(spots.last.music.name);
spots.removeLast();
resetPosition();
}
}

@ -1,8 +1,8 @@
import 'user.dart';
class Message {
User sender;
String senderId;
String content;
Message(this.sender, this.content);
Message(this.senderId, this.content);
}

@ -1,8 +1,15 @@
import 'package:dafl_project_flutter/services/database/user_modifier.dart';
class DatabaseUserModifier implements UserModifier {
@override
changeCurrentPassword(String userToModify, String newPass) {
// TODO: implement changeCurrentPassword
throw UnimplementedError();
}
@override
changeUsername(String userToModify, String newName) {
// TODO: implement changeUsername
throw UnimplementedError();
}
}

@ -1,57 +0,0 @@
import 'package:geolocator/geolocator.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:async';
import '../main.dart';
class Location {
static Future<Map<String, dynamic>> sendCurrentLocation() async {
Uri uri = Uri.parse("https://codefirst.iut.uca.fr/containers/php_script-dorianhodin/insertAndMakeListUser.php");
Map<String, dynamic> spot = {};
LocationPermission permission;
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.deniedForever) {
return Future.error('Location Not Available');
}
}
String actualUser = MyApp.controller.currentUser.usernameDafl;
String actualSong = await MyApp.api.getCurrentlyPlayingTrack();
Position current = await Geolocator.getCurrentPosition();
http.Response response = await http.post(uri, body: {
"id": actualUser.toString(),
"latitude": current.latitude.toString(),
"longitude": current.longitude.toString(),
"idMusic": actualSong.toString(),
});
var data = jsonDecode(response.body);
if (data == 2){
return Future.error("Failed to connect, connection timeout");
}else if (data == 3) {
return Future.error("POST method failed");
}else{
data.forEach((s) => spot.putIfAbsent(s['user'], () => s['music']));
return spot;
}
}
}

@ -1 +1,55 @@
class Location {}
import 'package:dafl_project_flutter/model/spot.dart';
import 'package:geolocator/geolocator.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:async';
import '../../main.dart';
class Location {
final Map _spots = {};
List<Spot> get spots {
List<Spot> spots = [];
_spots.forEach((key, value) {
spots.add(Spot(key, value));
});
return spots;
}
sendCurrentLocation() async {
Uri uri = Uri.parse(
"https://codefirst.iut.uca.fr/containers/php_script-dorianhodin/insertAndMakeListUser.php");
LocationPermission permission;
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.deniedForever) {
//TODO : handle this case
}
}
String actualUser = MyApp.controller.getIdDafl().toString();
String actualSong = MyApp.controller.getCurrentMusic();
Position current = await Geolocator.getCurrentPosition();
http.Response response = await http.post(uri, body: {
"id": actualUser,
"latitude": current.latitude.toString(),
"longitude": current.longitude.toString(),
"idMusic": actualSong,
});
var data = jsonDecode(response.body);
if (data == 2) {
return Future.error("Failed to connect, connection timeout");
} else if (data == 3) {
return Future.error("POST method failed");
} else {
data.forEach((s) => _spots.putIfAbsent(s['user'], () => s['music']));
}
}
}

@ -12,7 +12,7 @@ class ConversationPage extends StatefulWidget {
}
class _ConversationPageState extends State<ConversationPage> {
User destinataire = User("test1", '1234');
String destinataire = 'test';
List<Widget> messages = [];
bool isNull = true;
@ -20,13 +20,13 @@ class _ConversationPageState extends State<ConversationPage> {
void sendMessage(String content) {
setState(() {
messages
.add(messageWidget(Message(MyApp.controller.currentUser, content)));
messages.add(messageWidget(
Message(MyApp.controller.getIdDafl().toString(), content)));
});
}
Widget messageWidget(Message message) {
if (message.sender != MyApp.controller.currentUser) {
if (message.senderId != MyApp.controller.getIdDafl().toString()) {
return Align(
alignment: Alignment.centerLeft,
child: Container(
@ -374,8 +374,11 @@ class _ConversationPageState extends State<ConversationPage> {
height: 70,
child: ElevatedButton(
onPressed: () {
MyApp.controller.sendEmail(MyApp.controller.currentUser,
destinataire, currentValue, messageTextField.text);
MyApp.controller.sendEmail(
MyApp.controller.getIdDafl().toString(),
destinataire,
currentValue,
messageTextField.text);
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(

@ -39,17 +39,17 @@ class _DiscoveryWidgetState extends State<DiscoveryWidget> {
),
OutlinedButton(
onPressed: () {
MyApp.controller.currentUser.sortChoise =
!MyApp.controller.currentUser.sortChoise;
MyApp.controller.sortChoice =
!MyApp.controller.sortChoice;
rebuildAllChildren(context);
setState(() {});
},
style: OutlinedButton.styleFrom(
foregroundColor: Colors.grey,
shadowColor: Colors.black,
shape: CircleBorder(),
padding: EdgeInsets.all(24),
primary: Colors.grey),
child: MyApp.controller.currentUser.sortChoise
shape: const CircleBorder(),
padding: const EdgeInsets.all(24)),
child: MyApp.controller.sortChoice
? Image.asset(
'assets/images/date_sort_icon.png',
height: 25,
@ -70,7 +70,7 @@ class _DiscoveryWidgetState extends State<DiscoveryWidget> {
),
),
Expanded(
child: MyApp.controller.currentUser.discovery.isEmpty
child: MyApp.controller.getDiscoveries().isEmpty
? Center(
child: Image.asset(
'assets/images/EmptyDiscovery-Hint.png',
@ -119,7 +119,7 @@ class _DiscoveryListState extends State<DiscoveryList> {
@override
Widget build(BuildContext context) {
var listDiscoveries = MyApp.controller.getDiscoveries();
if (MyApp.controller.currentUser.sortChoise) {
if (MyApp.controller.sortChoice) {
listDiscoveries.sort((a, b) {
return a.date.compareTo(b.date);
});

@ -1,8 +1,5 @@
import 'package:text_scroll/text_scroll.dart';
import 'package:scroll_loop_auto_scroll/scroll_loop_auto_scroll.dart';
import '../../../main.dart';
import '../../../model/music.dart';
import './w_settings.dart';
@ -32,19 +29,18 @@ class MainPageProfil extends StatefulWidget {
}
class _MainPageProfilState extends State<MainPageProfil> {
String? username = MyApp.controller.currentUser.usernameDafl;
late Future<Map> data;
Future<Map> getdata() async {
return MyApp.api.getTrackInfo( await MyApp.api.getCurrentlyPlayingTrack());
String username = MyApp.controller.getIdDafl().toString();
late Future<Music> data;
Future<Music> getData() async {
return await MyApp.controller
.getCompleteMusic(MyApp.controller.getCurrentMusic());
}
@override
initState() {
initState() async {
super.initState();
username = MyApp.controller.currentUser.usernameDafl;
MyApp.controller.currentUser.actualiseCurrentMusic();
username = MyApp.controller.getIdDafl().toString();
}
@override
@ -86,14 +82,14 @@ class _MainPageProfilState extends State<MainPageProfil> {
],
),
child: Center(
child: Text(username![0],
child: Text(username[0],
style: const TextStyle(
color: Colors.white,
fontSize: 60,
fontWeight: FontWeight.w500),
textAlign: TextAlign.center))),
Text(
username!,
username,
style: const TextStyle(
color: Colors.white,
fontSize: 17,
@ -236,7 +232,7 @@ class _MainPageProfilState extends State<MainPageProfil> {
],
),
FutureBuilder(
future: getdata(),
future: getData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Container(
@ -251,43 +247,54 @@ class _MainPageProfilState extends State<MainPageProfil> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.fromLTRB(15, 0, 0, 0),
margin:
const EdgeInsets.fromLTRB(15, 0, 0, 0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(snapshot.data!['cover'],
child: Image.network(
snapshot.data!.linkCover,
height: 90,
width: 90,
))),
Container(
margin: const EdgeInsets.fromLTRB(12, 20, 0, 0),
margin:
const EdgeInsets.fromLTRB(12, 20, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
snapshot.data!['name'].length > 22?
SizedBox(width: 220,
snapshot.data!.name.length > 22
? SizedBox(
width: 220,
child: ScrollLoopAutoScroll(
delayAfterScrollInput: Duration(seconds: 1),
delay: Duration(seconds: 1),
delayAfterScrollInput:
const Duration(seconds: 1),
delay:
const Duration(seconds: 1),
duration: const Duration(
seconds: 100),
scrollDirection:
Axis.horizontal,
child: Text(
snapshot.data!['name'],
style: TextStyle(fontSize: 20,
snapshot.data!.name,
style: const TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold),
fontWeight:
FontWeight.bold),
),
duration: Duration(seconds: 100),
scrollDirection: Axis.horizontal,
),)
),
)
: Text(
snapshot.data!['name'],
style: TextStyle(fontSize: 20,
snapshot.data!.name,
style: const TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold),
),
Text(
snapshot.data!['artist'],
snapshot.data!.artist,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
@ -299,8 +306,7 @@ class _MainPageProfilState extends State<MainPageProfil> {
],
),
);
}
else{
} else {
return Container(
margin: const EdgeInsets.fromLTRB(0, 10, 0, 0),
height: height * 0.14,
@ -313,32 +319,40 @@ class _MainPageProfilState extends State<MainPageProfil> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.fromLTRB(15, 0, 0, 0),
margin:
const EdgeInsets.fromLTRB(15, 0, 0, 0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.asset("assets/images/loadingPlaceholder.gif",
child: Image.asset(
"assets/images/loadingPlaceholder.gif",
height: 90,
width: 90))),
Container(
margin: const EdgeInsets.fromLTRB(12, 20, 0, 0),
margin:
const EdgeInsets.fromLTRB(12, 20, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Container(
width: 150,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
borderRadius:
BorderRadius.circular(5.0),
color: Colors.grey.withOpacity(0.7),
),
),
SizedBox(height: 10,),
const SizedBox(
height: 10,
),
Container(
width: 100,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
borderRadius:
BorderRadius.circular(5.0),
color: Colors.grey.withOpacity(0.4),
),
),
@ -349,9 +363,7 @@ class _MainPageProfilState extends State<MainPageProfil> {
),
);
}
})
,
}),
],
),
),
@ -382,7 +394,7 @@ class _MainPageProfilState extends State<MainPageProfil> {
builder: (context) => const SettingsWidget()))
.then((value) => setState(() {
username =
MyApp.controller.currentUser.usernameDafl;
MyApp.controller.getIdDafl().toString();
}));
},
child: Row(
@ -418,5 +430,4 @@ class _MainPageProfilState extends State<MainPageProfil> {
),
);
}
}

@ -31,11 +31,9 @@ class _SpotsWidgetState extends State<SpotsWidget> {
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
MyApp.controller.currentUser.spots.isEmpty
image: NetworkImage(MyApp.controller.getSpots().isEmpty
? "https://i.imgur.com/Uovh293.png"
: MyApp.controller.currentUser.spots.last.music
.linkCover),
: MyApp.controller.getSpots().last.music.linkCover),
fit: BoxFit.cover,
),
),
@ -50,15 +48,8 @@ class _SpotsWidgetState extends State<SpotsWidget> {
),
Align(
alignment: FractionalOffset.bottomCenter,
child: MyApp.controller.currentUser.spots.isEmpty
? const Center(
child: SizedBox(
width: 300,
height: 300,
child: riv.RiveAnimation.asset(
'assets/images/search_spot_animation.riv'),
),
)
child: MyApp.controller.getSpots().isEmpty
? Container()
: OpenContainer(
closedColor: Colors.transparent,
closedElevation: 0,
@ -68,13 +59,19 @@ class _SpotsWidgetState extends State<SpotsWidget> {
},
openBuilder: (context, closeWidget) {
return const DisplayInfoWidget();
},
})),
const Center(
child: SizedBox(
width: 300,
height: 300,
child: riv.RiveAnimation.asset(
'assets/images/search_spot_animation.riv'),
),
),
Positioned(
top: height * 0.68,
width: width,
child: MyApp.controller.currentUser.spots.isEmpty
child: MyApp.controller.getSpots().isEmpty
? Container()
: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
@ -165,14 +162,16 @@ class _SpotsWidgetState extends State<SpotsWidget> {
)),
),
),
MyApp.controller.currentUser.spots.isEmpty?
SafeArea(child: Center(
MyApp.controller.getSpots().isEmpty
? SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
MyApp.controller.currentUser.spots.isEmpty?
Column(
crossAxisAlignment: CrossAxisAlignment.start,
MyApp.controller.getSpots().isEmpty
? Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
'Quelques instants...',
@ -181,32 +180,39 @@ class _SpotsWidgetState extends State<SpotsWidget> {
fontWeight: FontWeight.w500,
fontSize: 25),
),
const Padding(padding: EdgeInsets.fromLTRB(0, 5, 0, 0)),
const Padding(
padding:
EdgeInsets.fromLTRB(0, 5, 0, 0)),
Text(
'Nous cherchons des profils a vous proposer.',
style: TextStyle(
color: Colors.grey.withOpacity(0.4), fontSize: 15),
color: Colors.grey.withOpacity(0.4),
fontSize: 15),
),
],
) :
Container(),
]
)
),):
Padding(
: Container(),
])),
)
: Padding(
padding: const EdgeInsets.fromLTRB(20, 60, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(MyApp.controller.currentUser.spots.last.music.name,
Text(
MyApp.controller.getSpots().isEmpty
? ''
: MyApp.controller.getSpots().last.music.name,
style: TextStyle(
fontFamily: 'DMSans',
color: Colors.white.withOpacity(1),
fontSize: 20,
fontWeight: FontWeight.w800),
),
Text(MyApp.controller.currentUser.spots.last.music.artist,
Text(
MyApp.controller.getSpots().isEmpty
? ''
: MyApp.controller.getSpots().last.music.artist,
style: TextStyle(
fontFamily: 'DMSans',
color: Colors.white.withOpacity(1),
@ -221,12 +227,12 @@ class _SpotsWidgetState extends State<SpotsWidget> {
right: 0,
child: GestureDetector(
onTap: () {
MyApp.api.playTrack(
MyApp.controller.currentUser.spots.last.music.id);
MyApp.controller
.playTrack(MyApp.controller.getSpots().last.music.id);
},
child: SizedBox(
height: 40,
child: !MyApp.controller.currentUser.spots.isEmpty
child: MyApp.controller.getSpots().isEmpty
? Image.asset("assets/images/play_spotify_button.png")
: Container(),
),
@ -238,7 +244,7 @@ class _SpotsWidgetState extends State<SpotsWidget> {
Widget buildCards() {
final provider = Provider.of<CardProvider>(context);
final urlImages = provider.spotsList;
final urlImages = MyApp.controller.getSpots();
return Stack(
children: urlImages

@ -558,6 +558,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
time:
dependency: transitive
description:
name: time
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
typed_data:
dependency: transitive
description:

Loading…
Cancel
Save