parent
7b3b514770
commit
e049a265cd
@ -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{
|
||||
|
||||
|
||||
}
|
||||
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']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue