Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue in build_update_commands() when checking for commands attrs id. #835

Merged
merged 2 commits into from
Jan 13, 2023

Conversation

Ewen-Zippedscript
Copy link
Contributor

Fixed issue with if cmd.name == "add" and any(c for c in cmd.commands if c.attrs["id"] == ctrl.__uid):
because some commands may not have the id value so now it's `if cmd.name == "add" and any( c for c in cmd.commands if c.attrs.get("id") == ctrl.__uid ):

@CLAassistant
Copy link

CLAassistant commented Jan 9, 2023

CLA assistant check
All committers have signed the CLA.

@Ewen-Zippedscript
Copy link
Contributor Author

As far as I can tell the issue happens when replacing an existing control with an identical copy and since the copy doesn't have a uid yet it throws that error.

@FeodorFitsner
Copy link
Contributor

Would you share a repro code for that?

@Ewen-Zippedscript
Copy link
Contributor Author

I've written a script that throws the same error.

import flet as ft



class Field:
    def __init__(self,page:ft.Page):
        self.page = page
        self._controls = []
        
        self.control = None
        self._update()

    def setup(self):
        name = ft.TextField(label="Name",)
        f = ft.TextField(label="Second",)

        self._controls = [name,f]

    def _update(self,):
        if not self.control:
            self.setup()
            self.control = ft.Container(ft.Column(self._controls))
        try:
            self.control.update()
        except:
            pass
        # self.page.update()


class View:
    def __init__(self,page:ft.Page):
        self.page = page
        self._controls = []
        self.fields = []
        self.setup()
        self.view = ft.View("/",self._controls)

        self.add_field(None)
        self.add_field(None)
    def setup(self):
        self.add = ft.ElevatedButton("Add Row",on_click=self.add_field,col=4)
        self.single_field = ft.TextField(label="single_field",col=8)
        self._controls = [ft.ResponsiveRow([self.add, self.single_field]),]
        for field in self.fields:
            self._controls.append(
                ft.Column([
                    ft.Divider(color=ft.colors.BLACK26),
                    ft.ElevatedButton(
                        text=f"Remove field {self.fields.index(field)}",
                        icon=ft.icons.REMOVE_CIRCLE,
                        on_click=lambda _: self.remove_field(field))
                ]))
            self._controls.append(field.control)
    def add_field(self,e):
        self.fields.append(Field(self.page))
        self._update()
    def remove_field(self, degree):
            self.fields.remove(degree)
            self._update()
    def _update(self):
        self.setup()
        if self.view:
            self.view.controls = self._controls
        try:
            self.view.update()
        except:
            pass
        for i in self._controls:
            try:
                i.update()
            except:
                pass
        self.view.controls = self._controls
        self.page.update()

class FlutterApp:
    def __init__(self):
        self.page = None
        

    def main(self,page:ft.Page):
        self.page = page
        self.main_v = View(page)
        self.page.views.append(self.main_v.view)
        self.page.update()
        
    

app = FlutterApp()
ft.app(target=app.main,view=ft.FLET_APP)

@FeodorFitsner FeodorFitsner merged commit 4ee1416 into flet-dev:main Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants