add start_date and end_date
This commit is contained in:
parent
431b8d78ad
commit
bae64ebd35
@ -46,7 +46,8 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
String query = '';
|
String query = '';
|
||||||
List<Map<String, dynamic>> suggestions = [];
|
List<Map<String, dynamic>> suggestions = [];
|
||||||
TextEditingController inputGeo = TextEditingController();
|
TextEditingController inputGeo = TextEditingController();
|
||||||
TextEditingController Datepicker = TextEditingController();
|
TextEditingController startDatepicker = TextEditingController();
|
||||||
|
TextEditingController endDatepicker = TextEditingController();
|
||||||
|
|
||||||
// Fetching events from API
|
// Fetching events from API
|
||||||
static Future<List<Events>> getPosts() async {
|
static Future<List<Events>> getPosts() async {
|
||||||
@ -130,10 +131,21 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
DateTime currentDateTime = DateTime.now();
|
DateTime currentDateTime = DateTime.now();
|
||||||
var url = Uri.parse(
|
var url = Uri.parse(
|
||||||
"${globals.api}/events?current_datetime=${currentDateTime.toString()}");
|
"${globals.api}/events?current_datetime=${currentDateTime.toString()}");
|
||||||
if (Datepicker.text.isNotEmpty) {
|
if (startDatepicker.text.isNotEmpty) {
|
||||||
var date = DateTime.parse(formatDate(Datepicker.text));
|
var date = DateTime.parse(formatDate(startDatepicker.text));
|
||||||
url = Uri.parse("${globals.api}/events?date_event=${date.toString()}");
|
url = Uri.parse("${globals.api}/events?date_event=${date.toString()}");
|
||||||
}
|
}
|
||||||
|
if (endDatepicker.text.isNotEmpty) {
|
||||||
|
var date = DateTime.parse(formatDate(endDatepicker.text));
|
||||||
|
url = Uri.parse("${globals.api}/events?date_event=${date.toString()}");
|
||||||
|
}
|
||||||
|
if ((startDatepicker.text.isNotEmpty) &&
|
||||||
|
(endDatepicker.text.isNotEmpty)) {
|
||||||
|
var start_date = DateTime.parse(formatDate(startDatepicker.text));
|
||||||
|
var end_date = DateTime.parse(formatDate(endDatepicker.text));
|
||||||
|
url = Uri.parse(
|
||||||
|
"${globals.api}/events?start_date=${start_date.toString()}&end_date=${end_date.toString()}");
|
||||||
|
}
|
||||||
final response = await http.get(url, headers: {
|
final response = await http.get(url, headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
HttpHeaders.cookieHeader: "access_token=${accessToken}"
|
HttpHeaders.cookieHeader: "access_token=${accessToken}"
|
||||||
@ -320,15 +332,31 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
var url = Uri.parse("${globals.api}/events/search"
|
var url = Uri.parse("${globals.api}/events/search"
|
||||||
"?min_lat=$minLat&max_lat=$maxLat"
|
"?min_lat=$minLat&max_lat=$maxLat"
|
||||||
"&min_lon=$minLon&max_lon=$maxLon¤t_datetime=${currentDate.toString()}");
|
"&min_lon=$minLon&max_lon=$maxLon¤t_datetime=${currentDate.toString()}");
|
||||||
if (Datepicker.text.isNotEmpty) {
|
if (startDatepicker.text.isNotEmpty) {
|
||||||
var date = DateTime.parse(formatDate(Datepicker.text));
|
var date = DateTime.parse(formatDate(startDatepicker.text));
|
||||||
print("date_event ${date.toString()}");
|
|
||||||
url = Uri.parse("${globals.api}/events/search"
|
url = Uri.parse("${globals.api}/events/search"
|
||||||
"?min_lat=$minLat&max_lat=$maxLat"
|
"?min_lat=$minLat&max_lat=$maxLat"
|
||||||
"&min_lon=$minLon&max_lon=$maxLon&date_event=" +
|
"&min_lon=$minLon&max_lon=$maxLon&date_event=" +
|
||||||
date.toString());
|
date.toString());
|
||||||
}
|
}
|
||||||
|
if (endDatepicker.text.isNotEmpty) {
|
||||||
|
var date = DateTime.parse(formatDate(endDatepicker.text));
|
||||||
|
url = Uri.parse("${globals.api}/events/search"
|
||||||
|
"?min_lat=$minLat&max_lat=$maxLat"
|
||||||
|
"&min_lon=$minLon&max_lon=$maxLon&date_event=" +
|
||||||
|
date.toString());
|
||||||
|
}
|
||||||
|
if ((startDatepicker.text.isNotEmpty) &&
|
||||||
|
(endDatepicker.text.isNotEmpty)) {
|
||||||
|
var start_date = DateTime.parse(formatDate(startDatepicker.text));
|
||||||
|
var end_date = DateTime.parse(formatDate(endDatepicker.text));
|
||||||
|
url = Uri.parse("${globals.api}/events/search"
|
||||||
|
"?min_lat=$minLat&max_lat=$maxLat"
|
||||||
|
"&min_lon=$minLon&max_lon=$maxLon&start_date=" +
|
||||||
|
start_date.toString() +
|
||||||
|
"&end_date=" +
|
||||||
|
end_date.toString());
|
||||||
|
}
|
||||||
final response = await http.get(url, headers: {
|
final response = await http.get(url, headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
HttpHeaders.cookieHeader: "access_token=$accessToken"
|
HttpHeaders.cookieHeader: "access_token=$accessToken"
|
||||||
@ -355,15 +383,33 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onTapFunctionDatePicker({required BuildContext context}) async {
|
onTapFunctionDatePicker(
|
||||||
|
{required BuildContext context, String position = ""}) async {
|
||||||
DateTime dateEvent = DateTime.now();
|
DateTime dateEvent = DateTime.now();
|
||||||
|
if (startDatepicker.text.isNotEmpty) {
|
||||||
|
dateEvent = DateTime.parse(formatDate(startDatepicker.text));
|
||||||
|
}
|
||||||
|
|
||||||
DateTime? pickedDate = await showDatePicker(
|
DateTime? pickedDate = await showDatePicker(
|
||||||
context: context, firstDate: dateEvent, lastDate: DateTime(2104));
|
context: context, firstDate: dateEvent, lastDate: DateTime(2104));
|
||||||
if (pickedDate == null) return;
|
if (pickedDate == null) return;
|
||||||
Datepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate);
|
if (position == "start") {
|
||||||
|
startDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate);
|
||||||
|
} else if (position == "end") {
|
||||||
|
endDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate);
|
||||||
|
}
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
prefs.setString("date_event", Datepicker.text);
|
if (startDatepicker.text.isNotEmpty) {
|
||||||
|
prefs.setString("date_event", startDatepicker.text);
|
||||||
|
prefs.setString("start_date", startDatepicker.text);
|
||||||
|
}
|
||||||
|
if (endDatepicker.text.isNotEmpty) {
|
||||||
|
prefs.setString("date_event", endDatepicker.text);
|
||||||
|
prefs.setString("end_date", endDatepicker.text);
|
||||||
|
}
|
||||||
|
if ((startDatepicker.text.isNotEmpty) && (endDatepicker.text.isNotEmpty)) {
|
||||||
|
prefs.remove("date_event");
|
||||||
|
}
|
||||||
if (inputGeo.text.isEmpty) {
|
if (inputGeo.text.isEmpty) {
|
||||||
_fetchInitialData();
|
_fetchInitialData();
|
||||||
} else {
|
} else {
|
||||||
@ -371,25 +417,39 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Padding _BuildDateField() {
|
Padding _buildDateField(String position) {
|
||||||
|
TextEditingController datePicker = startDatepicker;
|
||||||
|
String hintText = "Date de début";
|
||||||
|
if (position == "end") {
|
||||||
|
datePicker = endDatepicker;
|
||||||
|
hintText = "Date de fin";
|
||||||
|
}
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: Datepicker,
|
controller: datePicker,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: const Icon(Icons.clear),
|
icon: const Icon(Icons.clear),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
setState(() {
|
||||||
|
datePicker.text = '';
|
||||||
|
});
|
||||||
SharedPreferences prefs =
|
SharedPreferences prefs =
|
||||||
await SharedPreferences.getInstance();
|
await SharedPreferences.getInstance();
|
||||||
|
if (position == "start") {
|
||||||
prefs.remove("date_event");
|
prefs.remove("start_date");
|
||||||
setState(() {
|
}
|
||||||
Datepicker.text = '';
|
if (position == "end") {
|
||||||
});
|
prefs.remove("end_date");
|
||||||
|
}
|
||||||
|
if ((startDatepicker.text.isEmpty) &&
|
||||||
|
(endDatepicker.text.isEmpty)) {
|
||||||
|
prefs.remove("date_event");
|
||||||
|
}
|
||||||
if (inputGeo.text.isNotEmpty) {
|
if (inputGeo.text.isNotEmpty) {
|
||||||
fetchPostsByLocation();
|
fetchPostsByLocation();
|
||||||
} else {
|
} else {
|
||||||
@ -397,8 +457,9 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
hintText: 'Recherche par date'),
|
hintText: hintText),
|
||||||
onTap: () => onTapFunctionDatePicker(context: context)),
|
onTap: () =>
|
||||||
|
onTapFunctionDatePicker(context: context, position: position)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,7 +562,8 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
_buildGeographicalZoneSearchField(),
|
_buildGeographicalZoneSearchField(),
|
||||||
_BuildDateField(),
|
_buildDateField("start"),
|
||||||
|
_buildDateField("end"),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: FutureBuilder<List<Events>>(
|
child: FutureBuilder<List<Events>>(
|
||||||
future: postsFuture,
|
future: postsFuture,
|
||||||
|
@ -94,12 +94,20 @@ class SearchDelegateExample extends SearchDelegate {
|
|||||||
String parameter = "current_datetime";
|
String parameter = "current_datetime";
|
||||||
String currentDate = DateTime.now().toString();
|
String currentDate = DateTime.now().toString();
|
||||||
String date = prefs.getString("date_event") ?? "";
|
String date = prefs.getString("date_event") ?? "";
|
||||||
|
String startDate = prefs.getString("start_date") ?? "";
|
||||||
|
String endDate = prefs.getString("end_date") ?? "";
|
||||||
if (date.isNotEmpty) {
|
if (date.isNotEmpty) {
|
||||||
currentDate = DateTime.parse(formatDate(date)).toString();
|
currentDate = DateTime.parse(formatDate(date)).toString();
|
||||||
parameter = "date_event";
|
parameter = "date_event";
|
||||||
}
|
}
|
||||||
|
String parameterString = "${parameter}=${currentDate}";
|
||||||
|
if ((startDate.isNotEmpty) && (endDate.isNotEmpty)) {
|
||||||
|
startDate = DateTime.parse(formatDate(startDate)).toString();
|
||||||
|
endDate = DateTime.parse(formatDate(endDate)).toString();
|
||||||
|
parameterString = "start_date=${startDate}&end_date=${endDate}";
|
||||||
|
}
|
||||||
var url = Uri.parse(
|
var url = Uri.parse(
|
||||||
"${globals.api}/events/search?item=${query}&${parameter}=${currentDate}");
|
"${globals.api}/events/search?item=${query}&${parameterString}");
|
||||||
if ((latitude != 0.0) && (longitude != 0.0)) {
|
if ((latitude != 0.0) && (longitude != 0.0)) {
|
||||||
// Now use the latitude and longitude to get events within a 50km radius
|
// Now use the latitude and longitude to get events within a 50km radius
|
||||||
double radiusInKm = 50;
|
double radiusInKm = 50;
|
||||||
@ -111,7 +119,7 @@ class SearchDelegateExample extends SearchDelegate {
|
|||||||
double maxLon = longitude + lonDistance;
|
double maxLon = longitude + lonDistance;
|
||||||
// Construct the search URL with the item query and latitude/longitude bounds
|
// Construct the search URL with the item query and latitude/longitude bounds
|
||||||
url = Uri.parse(
|
url = Uri.parse(
|
||||||
"${globals.api}/events/search?item=${query}&min_lat=${minLat}&max_lat=${maxLat}&min_lon=${minLon}&max_lon=${maxLon}&${parameter}=${currentDate}");
|
"${globals.api}/events/search?item=${query}&min_lat=${minLat}&max_lat=${maxLat}&min_lon=${minLon}&max_lon=${maxLon}&${parameterString}");
|
||||||
}
|
}
|
||||||
final response = await http.get(url, headers: {
|
final response = await http.get(url, headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user