-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPractice
154 lines (139 loc) · 7 KB
/
Practice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import flet as ft
def main(page: ft.Page):
page.title = "Picture Viewer App"
page.padding = 20
emal="jack"
password="password123"
name_ = ft.TextField(label="Name", width=300)
data_ = ft.TextField(label="Date of Birth", width=300, read_only=False)
sex_ = ft.RadioGroup(
content=ft.Row([
ft.Radio(value="Male", label="Male"),
ft.Radio(value="Female", label="Female"),
ft.Radio(value="Others", label="Others"),
])
)
address_ = ft.TextField(label="Address", width=300)
country_ = ft.Dropdown(
label="Country",
options=[
ft.dropdown.Option("USA"),
ft.dropdown.Option("Finland"),
ft.dropdown.Option("China"),
ft.dropdown.Option("Nigeria"),
ft.dropdown.Option("Ghana"),
ft.dropdown.Option("India"),
ft.dropdown.Option("France"),
ft.dropdown.Option("South Korea"),
],
width=300
)
# password=123456
# name="jack"
def route_change(route):
page.views.clear()
# Login Page
if page.route == "/":
email_ = ft.TextField(label="Email", width=300)
password_ = ft.TextField(label="Password", password=True, width=300)
error_msg = ft.Text("", color=ft.colors.RED)
def login_clicked(e):
if not email_.value or not password_.value:
error_msg.value = "Email and password cannot be empty!"
elif emal != email_.value:
error_msg.value = "Please give the right email!"
elif password !=password_.value :
error_msg.value = "Please give the right password!"
elif password !=password_.value and emal != email_.value:
error_msg.value = "Please give the right password and email!"
else:
error_msg.value = ""
page.go("/form")
page.update()
page.views.append(
ft.View(
"/",
[
ft.AppBar(title=ft.Text("Login"), bgcolor=ft.colors.SURFACE_VARIANT),
email_,
password_,
ft.ElevatedButton("Login", on_click=login_clicked),
error_msg,
],
)
)
# Form Page
elif page.route == "/form":
def select_date(e):
def set_date(d):
data_.value = str(d.data.split('T')[0])
page.update()
page.dialog = ft.DatePicker(on_change=set_date)
page.dialog.open = True
page.update()
dob_picker = ft.IconButton(icon=ft.icons.CALENDAR_MONTH, on_click=select_date)
def submit_form(e):
if all([name_.value, data_.value, sex_.value, address_.value, country_.value]):
page.go("/details")
else:
page.snack_bar = ft.SnackBar(ft.Text("Please fill all fields!"))
page.snack_bar.open = True
page.update()
page.views.append(
ft.View(
"/form",
[
ft.AppBar(title=ft.Text("Form"), bgcolor=ft.colors.SURFACE_VARIANT, leading=ft.IconButton(ft.icons.ARROW_BACK, on_click=lambda _: page.go("/"))),
name_,
ft.Row([data_, dob_picker], alignment=ft.MainAxisAlignment.START),
ft.Text("Sex:"),
sex_,
address_,
country_,
ft.ElevatedButton("Create", on_click=submit_form),
],
)
)
# Details Page
elif page.route == "/details":
page.views.append(
ft.View(
"/details",
[
ft.AppBar(title=ft.Text("Details"), bgcolor=ft.colors.SURFACE_VARIANT, leading=ft.IconButton(ft.icons.ARROW_BACK, on_click=lambda _: page.go("/form"))),
ft.Card(
content=ft.Container(
content=ft.Column(
[
ft.Text(f"Name: {name_.value}", style=ft.TextThemeStyle.TITLE_LARGE),
ft.Text(f"Date of Birth: {data_.value}", style=ft.TextThemeStyle.BODY_MEDIUM),
ft.Text(f"Sex: {sex_.value}", style=ft.TextThemeStyle.BODY_MEDIUM),
ft.Text(f"Address: {address_.value}", style=ft.TextThemeStyle.BODY_MEDIUM),
ft.Text(f"Country: {country_.value}", style=ft.TextThemeStyle.BODY_MEDIUM),
]
),
padding=20,
bgcolor=ft.colors.SURFACE,
border_radius=10,
shadow=ft.BoxShadow(
blur_radius=10,
spread_radius=2,
color=ft.colors.BLACK12,
)
),
),
ft.ElevatedButton("Return", on_click=lambda _: page.go("/form")),
],
)
)
page.update()
def view_pop(view):
page.views.pop()
top_view = page.views[-1]
page.go(top_view.route)
# Set route handling
page.on_route_change = route_change
page.on_view_pop = view_pop
page.go(page.route)
ft.app(main, view=ft.AppView.WEB_BROWSER)