fix datepicker
This commit is contained in:
parent
44a0691e31
commit
00a9125eb2
@ -87,38 +87,41 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
|
||||
Future<void> searchEvents(String json, String imagePath) async {
|
||||
print(json.replaceAll("'''json", '').replaceAll("'''", ""));
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
try {
|
||||
Map<String, dynamic> jsonData =
|
||||
jsonDecode(json.replaceAll("```json", '').replaceAll("```", ""));
|
||||
print("json : ${jsonData}");
|
||||
var name = jsonData["name"];
|
||||
print("name : ${name}");
|
||||
var place = jsonData["place"];
|
||||
var accessToken = prefs.getString("access_token") ?? "";
|
||||
|
||||
Map<String, dynamic> jsonData =
|
||||
jsonDecode(json.replaceAll("```json", '').replaceAll("```", ""));
|
||||
print("json : ${jsonData}");
|
||||
var name = jsonData["name"];
|
||||
print("name : ${name}");
|
||||
var place = jsonData["place"];
|
||||
var accessToken = prefs.getString("access_token") ?? "";
|
||||
if (accessToken.isNotEmpty) {
|
||||
var urlGet = Uri.parse("${globals.api}/events?name=${name}");
|
||||
|
||||
if (accessToken.isNotEmpty) {
|
||||
var urlGet = Uri.parse("${globals.api}/events?name=${name}");
|
||||
|
||||
var responseGet = await http.get(urlGet,
|
||||
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
|
||||
if (responseGet.statusCode == 200) {
|
||||
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
||||
print("reponse http : ${events.length}");
|
||||
if (events.length == 0) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => UpdateeventImage(
|
||||
events: jsonData, imagePath: imagePath)));
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ItemMenu(title: events[0]["id"])));
|
||||
var responseGet = await http.get(urlGet,
|
||||
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
|
||||
if (responseGet.statusCode == 200) {
|
||||
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
||||
print("reponse http : ${events.length}");
|
||||
if (events.length == 0) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => UpdateeventImage(
|
||||
events: jsonData, imagePath: imagePath)));
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ItemMenu(title: events[0]["id"])));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showErrorDialog(context, "Erreur de token");
|
||||
}
|
||||
} else {
|
||||
showErrorDialog(context, "Erreur de token");
|
||||
} catch (e) {
|
||||
showErrorDialog(context, "Erreur de format de donnée fourni par l'IA");
|
||||
}
|
||||
|
||||
//showDescImageAddDialog(context, message);
|
||||
|
@ -70,10 +70,16 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
if (position == "end") {
|
||||
date = "end_date";
|
||||
}
|
||||
DateTime dateEvent;
|
||||
if (widget.events[date].toString().isEmpty) {
|
||||
dateEvent = DateTime.now();
|
||||
} else {
|
||||
dateEvent = DateTime.parse(widget.events[date]);
|
||||
}
|
||||
DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
firstDate: DateTime.parse(widget.events[date]),
|
||||
initialDate: DateTime.parse(widget.events[date]),
|
||||
firstDate: dateEvent,
|
||||
initialDate: dateEvent,
|
||||
lastDate: DateTime(2104));
|
||||
if (pickedDate == null) return;
|
||||
if (position == "start") {
|
||||
@ -90,10 +96,14 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
if (position == "end") {
|
||||
date = "end_date";
|
||||
}
|
||||
TimeOfDay? pickedDate = await showTimePicker(
|
||||
context: context,
|
||||
initialTime:
|
||||
TimeOfDay.fromDateTime(DateTime.parse(widget.events[date])));
|
||||
TimeOfDay timeEvent;
|
||||
if (widget.events[date].toString().isEmpty) {
|
||||
timeEvent = TimeOfDay.now();
|
||||
} else {
|
||||
timeEvent = TimeOfDay.fromDateTime(DateTime.parse(widget.events[date]));
|
||||
}
|
||||
TimeOfDay? pickedDate =
|
||||
await showTimePicker(context: context, initialTime: timeEvent);
|
||||
if (pickedDate == null) return;
|
||||
if (position == "start") {
|
||||
startTimepicker.text = pickedDate.format(context);
|
||||
@ -274,16 +284,18 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
inputName.text = convertNulltoEmptyString(widget.events["name"]);
|
||||
inputGeo.text = convertNulltoEmptyString(widget.events["place"]);
|
||||
inputDesc.text = convertNulltoEmptyString(widget.events["description"]);
|
||||
|
||||
DateTime pickedStartDate =
|
||||
DateTime.parse(convertNulltoEmptyString(widget.events["start_date"]));
|
||||
DateTime pickedEndDate =
|
||||
DateTime.parse(convertNulltoEmptyString(widget.events["end_date"]));
|
||||
|
||||
startDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedStartDate);
|
||||
endDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedEndDate);
|
||||
startTimepicker.text = DateFormat("HH-mm").format(pickedStartDate);
|
||||
endTimepicker.text = DateFormat("HH-mm").format(pickedEndDate);
|
||||
if (widget.events["start_date"].toString().isNotEmpty) {
|
||||
DateTime pickedStartDate =
|
||||
DateTime.parse(convertNulltoEmptyString(widget.events["start_date"]));
|
||||
startDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedStartDate);
|
||||
startTimepicker.text = DateFormat("HH-mm").format(pickedStartDate);
|
||||
}
|
||||
if (widget.events["end_date"].toString().isNotEmpty) {
|
||||
DateTime pickedEndDate =
|
||||
DateTime.parse(convertNulltoEmptyString(widget.events["end_date"]));
|
||||
endDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedEndDate);
|
||||
endTimepicker.text = DateFormat("HH-mm").format(pickedEndDate);
|
||||
}
|
||||
initialTags = List<String>.from(widget.events['tags'] as List);
|
||||
initialOrga = List<String>.from(widget.events['organizers'] as List);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user