Closed Klu1d closed 3 weeks ago
The date you are using is in a wrong format. Accepted formats: https://api.flutter.dev/flutter/dart-core/DateTime/parse.html
Will make some improvements to show a more informative error message.
Accepted formats: https://api.flutter.dev/flutter/dart-core/DateTime/parse.html
class TimeRange: def __init__(self, start_date, end_date): #self.start_date = datetime.strptime(events[0]['date_start'].replace(' ', '_')start_date, '%Y-%m-%d_%H:%M:%S') self.start_date = datetime.strptime(start_date, '%Y-%m-%d_%H:%M:%S') self.end_date = datetime.strptime(end_date, '%Y-%m-%d_%H:%M:%S')
print(self.start_date)
![image](https://github.com/user-attachments/assets/0beb16f7-7d8d-4c36-84e7-896dd820667d)
My format is correct. Here is the output of the variable self.start_date after converting it to the datetime type.
I added print and output one of the approved datetime formats.
Point out the mistake to me, otherwise I don't understand.
However, if you put the following instruction in the body of the click function, it will be displayed correctly:
def main(page: ft.Page):
def click(e):
page.open(ft.DatePicker(
current_date=time_range.start_date,
first_date=copy.copy(time_range.start_date),
last_date=time_range.end_date,
))
page.update()
but If you use what is specified initially, it won't work.
Duplicate Check
Describe the bug
I get a gray screen when I press the button
Code sample
Code
```python import copy import flet as ft from datetime import datetime, timedelta style_button = { 'height': 40, 'icon': ft.icons.CALENDAR_MONTH, 'bgcolor': 'secondarycontainer, 0.6', 'style': ft.ButtonStyle(shape=ft.RoundedRectangleBorder(radius=10)), } class Event: pass class TimeRange: def __init__(self, start_date, end_date): #self.start_date = datetime.strptime(events[0]['date_start'].replace(' ', '_')start_date, '%Y-%m-%d_%H:%M:%S') self.start_date = datetime.strptime(start_date, '%Y-%m-%d_%H:%M:%S') self.end_date = datetime.strptime(end_date, '%Y-%m-%d_%H:%M:%S') self.current_start_date = copy.copy(start_date) self.current_end_date = copy.copy(end_date) self.start_date_picker = ft.DatePicker( current_date=self.start_date, first_date=copy.copy(start_date), last_date=self.end_date, on_change=self.__on_change_start_date, ) self.end_date_picker = ft.DatePicker( current_date=copy.copy(end_date), first_date=self.start_date, last_date=self.end_date, on_change=self.__on_change_end_date, ) def is_within_range(self, events: list[Event]) -> list: for event in events: event_date = datetime.strptime(event.date_start, '%Y-%m-%d_%H:%M:%S') if self.start_date <= event_date <= self.end_date: event.visible = True event.data = 'visible' else: event.visible = False event.data = None return events def get_start_date(self) -> str: return self.start_date.strftime('%d %B %Y') def get_end_date(self) -> str: return self.end_date.strftime('%d %B %Y') def __on_change_start_date(self, e: ft.ControlEvent): self.start_date = e.control.value self.start_date_picker.current_date = self.start_date self.start_date_picker.first_date = self.start_date self.end_date_picker.first_date = self.start_date self.update() def __on_change_end_date(self, e: ft.ControlEvent): self.end_date = e.control.value self.end_date_picker.current_date = self.end_date self.end_date_picker.last_date = self.end_date self.start_date_picker.last_date = self.end_date self.update() def main(page: ft.Page): def click(e): page.open(time_range.start_date_picker) page.update() time_range = TimeRange('2024-03-04_12:23:23'.replace(' ', '_'), '2024-05-04_12:23:23'.replace(' ', '_'),) el_b = ft.ElevatedButton(time_range.get_start_date(), on_click=click) page.add(el_b) ft.app(main) ```To reproduce
Click button
Expected behavior
Open TimeRange attribute self.start_date_picker
Screenshots / Videos
Operating System
Linux
Operating system details
Debian 12
Flet version
0.24.1
Regression
I'm not sure / I don't know
Suggestions
No response
Logs
Logs
```console [Paste your logs here] ```Additional details
No response