elsamueldev commited on
Commit
aba213a
1 Parent(s): 386e947

better code

Browse files
Files changed (1) hide show
  1. main.py +14 -21
main.py CHANGED
@@ -1,6 +1,4 @@
1
  import flet as ft
2
- from flet import TextField, ElevatedButton
3
- from flet_core import ControlEvent
4
  import flet_fastapi
5
 
6
  async def main(page: ft.Page) -> None:
@@ -10,42 +8,37 @@ async def main(page: ft.Page) -> None:
10
  title=ft.Text("This doesn't work yet!"), on_dismiss=lambda e: print("Dialog dismissed!")
11
  )
12
 
13
- async def open_dlg(e: ControlEvent):
14
- page.dialog = dlg
 
15
  dlg.open = True
16
  await page.update_async()
17
 
18
- question: TextField = TextField(label="Question", text_align=ft.TextAlign.LEFT, width=200)
19
- answer: TextField = TextField(label="Answer", text_align=ft.TextAlign.LEFT, width=200)
20
 
21
- button_submit: ElevatedButton = ElevatedButton(text="Send", disabled=True)
22
 
23
- async def validate(e: ControlEvent) -> None:
24
  if all((question.value, answer.value)):
25
- button_submit.disabled = False
26
  else:
27
- button_submit.disabled = True
28
 
29
  await page.update_async()
30
 
31
- async def submit(e: ControlEvent) -> None:
32
  await open_dlg(e)
33
 
34
  question.on_change = validate
35
  answer.on_change = validate
36
- button_submit.on_click = submit
37
-
38
 
39
- await page.add_async(
40
- ft.Container(question, alignment=ft.alignment.center)
41
- )
42
-
43
- await page.add_async(
44
- ft.Container(answer, alignment=ft.alignment.center)
45
- )
46
 
47
  await page.add_async(
48
- ft.Container(button_submit, alignment=ft.alignment.center)
 
 
49
  )
50
 
51
  app = flet_fastapi.app(main) # type: ignore
 
1
  import flet as ft
 
 
2
  import flet_fastapi
3
 
4
  async def main(page: ft.Page) -> None:
 
8
  title=ft.Text("This doesn't work yet!"), on_dismiss=lambda e: print("Dialog dismissed!")
9
  )
10
 
11
+ await page.add_async(dlg)
12
+
13
+ async def open_dlg(e: ft.ControlEvent) -> None:
14
  dlg.open = True
15
  await page.update_async()
16
 
17
+ question = ft.TextField(label="Question", text_align=ft.TextAlign.LEFT, width=200)
18
+ answer = ft.TextField(label="Answer", text_align=ft.TextAlign.LEFT, width=200)
19
 
20
+ submit_button = ft.ElevatedButton(text="Send", disabled=True)
21
 
22
+ async def validate(e: ft.ControlEvent) -> None:
23
  if all((question.value, answer.value)):
24
+ submit_button.disabled = False
25
  else:
26
+ submit_button.disabled = True
27
 
28
  await page.update_async()
29
 
30
+ async def submit(e: ft.ControlEvent) -> None:
31
  await open_dlg(e)
32
 
33
  question.on_change = validate
34
  answer.on_change = validate
35
+ submit_button.on_click = submit
 
36
 
 
 
 
 
 
 
 
37
 
38
  await page.add_async(
39
+ ft.Container(question, alignment=ft.alignment.center),
40
+ ft.Container(answer, alignment=ft.alignment.center),
41
+ ft.Container(submit_button, alignment=ft.alignment.center)
42
  )
43
 
44
  app = flet_fastapi.app(main) # type: ignore