{user_link}", italic=False, weight='bold'))
page.add(ShortLinkRow(shortened_link=shortener.tinyurl.short(user_link), link_source="By tinyurl.com"))
page.add(ShortLinkRow(shortened_link=shortener.chilpit.short(user_link), link_source="By chilp.it"))
page.add(ShortLinkRow(shortened_link=shortener.clckru.short(user_link), link_source="By clck.ru"))
page.add(ShortLinkRow(shortened_link=shortener.dagd.short(user_link), link_source="By da.dg"))
except Exception as exception: # the error might be that a url shortening service from pyshorteners failed to shorten our url
print(exception)
# inform the user that an error has occurred
page.show_snack_bar(
ft.SnackBar(
ft.Text("Sorry, but an error occurred. Please retry, or refresh the page."),
open=True
)
)
else: # if the textfield is empty (no text)
# inform the user
page.show_snack_bar(
ft.SnackBar(
ft.Text("Please enter a URL in the field!"),
open=True
)
)
text_field = ft.TextField(
value='https://github.com/ndonkoHenri', # a test link
label="Long URL", # the field's label
hint_text="type long url here", # the field's hint-text
max_length=200, # the maximum length of inputted links
keyboard_type="url", # the field's keyboard type
# 'shorten' is the function to be called on occurrence of some events
suffix=ft.FilledButton("Shorten!", on_click=shorten), # event: button clicked
on_submit=shorten # event: 'enter' key pressed
)
page.add(
text_field,
ft.Text("Generated URLs:", weight="bold", size=23)
) # add our textfield to the page/UI