OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

routing in Class of Flet

  • Thread starter Thread starter Amirreza
  • Start date Start date
A

Amirreza

Guest
I am customizing the ToDo project that is on the Flet framework website. In a part of the code, I want to be routed to another page when the user clicks on the login button. I checked the routing example codes on the Flet website, but I could not use it in my project (probably because I have poor class writing). So far, I managed to write the program in such a way that when the user clicks on the login button, ":|" be printed Can anyone help me with this? code:

Code:
import flet as ft

class TodoApp(UserControl):
    def build(self):
        # application's root control (i.e. "view") containing all other controls
        return Column(
            # width=1000,
            controls=[
                Row(
                    [
                        ElevatedButton(text="Login/SignUp",
                                       tooltip="login", color='green', on_click=self.route_change),
                        Text(
                            value="ToDo", style=TextThemeStyle.HEADLINE_MEDIUM, color='green')
                    ],
                    alignment=MainAxisAlignment.SPACE_BETWEEN,
                ),
            ],
        )

    async def route_change(self, e):
        print(':|')
async def main(page: Page):
    page.title = "ToDo App"
    page.horizontal_alignment = CrossAxisAlignment.CENTER
    page.scroll = ScrollMode.ADAPTIVE
    # create app control and add it to the page
    await page.add_async(TodoApp())


ft.app(main, view=AppView.WEB_BROWSER)

I tried to put the routing codes in the corresponding function (when it is clicked) but it was not successful also i tried flet-route but i cant work with it!
<p>I am customizing the ToDo project that is on the Flet framework website.
In a part of the code, I want to be routed to another page when the user clicks on the login button. I checked the <a href="https://flet.dev/blog/navigation-and-routing/" rel="nofollow noreferrer">routing example codes on the Flet website</a>, but I could not use it in my project (probably because I have poor class writing).
So far, I managed to write the program in such a way that when the user clicks on the login button, ":|" be printed
Can anyone help me with this?
code:</p>
<pre><code>import flet as ft

class TodoApp(UserControl):
def build(self):
# application's root control (i.e. "view") containing all other controls
return Column(
# width=1000,
controls=[
Row(
[
ElevatedButton(text="Login/SignUp",
tooltip="login", color='green', on_click=self.route_change),
Text(
value="ToDo", style=TextThemeStyle.HEADLINE_MEDIUM, color='green')
],
alignment=MainAxisAlignment.SPACE_BETWEEN,
),
],
)

async def route_change(self, e):
print(':|')
async def main(page: Page):
page.title = "ToDo App"
page.horizontal_alignment = CrossAxisAlignment.CENTER
page.scroll = ScrollMode.ADAPTIVE
# create app control and add it to the page
await page.add_async(TodoApp())


ft.app(main, view=AppView.WEB_BROWSER)

</code></pre>
<p>I tried to put the routing codes in the corresponding function (when it is clicked) but it was not successful
also i tried flet-route but i cant work with it!</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top