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

Add 'key' parameter to PaneItem.. #656

Closed
arrowxpr opened this issue Dec 20, 2022 · 3 comments · Fixed by #660
Closed

Add 'key' parameter to PaneItem.. #656

arrowxpr opened this issue Dec 20, 2022 · 3 comments · Fixed by #660
Labels
enhancement New feature or request

Comments

@arrowxpr
Copy link

Is your feature request related to a problem? Please describe.

I have been using NavigationPane with some static PanItems as part of my application's home page. I later used the same widget to build something dynamic, generating PanItems based on some data model.. Now I think the idea is clear. But the problem is that PanItem lacks the key parameter, and that causes my widgets to recreate themselves on every setState call..

But what is the next problem that follows? Well, Imagine I have a PanItem widget that contains a textfield, and let's say I update the data model whenever the textfield's value changes... now since my PanItems come from the data model, my widget gets recreated and the textfield loses its focus, and that is not a desirable behavior.

Describe the solution you'd like
Adding key parameter to the PanItem widget, or any other approach to solve the addressed issue, is much appreciated.

Describe alternatives you've considered
In the meantime I'm using PageView widget to achieve a sort of desirable outcome.

Additional context
Sample code to replicate the issue

class Test extends StatefulWidget {
  const Test({Key? key}) : super(key: key);

  @override
  State<Test> createState() => _TestState();
}

class _TestState extends State<Test> {
  int index = 0;

  @override
  Widget build(BuildContext context) {
    return NavigationView(
      pane: NavigationPane(
          selected: index,
          onChanged: (i) {
            setState(() {
              index = i;
            });
          },
          items: [
            ...List.generate(
                7,
                (index) => PaneItem(
                      /// I wish the 'key' parameter existed here :(.... Will it prevent the Kaboom though?
                      title: const Text('title'),
                      icon: const Icon(FluentIcons.radio_bullet),
                      body: Center(
                        child: TextBox(
                          header: index.toString(),
                          onChanged: (value) {
                            setState(() {
                              /// KABOOM.. WE LOSE TextBox's FOCUS HERE!!!
                            });
                          },
                        ),
                      ),
                    ))
          ]),
    );
  }
}

Share your thoughts
Thank you!

@bdlukaa bdlukaa added the enhancement New feature or request label Dec 22, 2022
@codeeuser
Copy link

I have this issue on iPad iOS Simulator but work properly on iPhone iOS and macOS. I am not sure the root cause and hope will be resolved as soon as possible.

As I reproduced the issue, i found that the TextBox has setted autofocus true which give me OK as a workaround.

@bdlukaa bdlukaa mentioned this issue Dec 23, 2022
3 tasks
@bdlukaa
Copy link
Owner

bdlukaa commented Dec 23, 2022

Hey! Can you check if #660 fixes the issue?

@arrowxpr
Copy link
Author

Hey! Thank you for the response. I just performed a quick test on that, it looks like the key parameter accepts GlobalKey! I went with it but the issue still persisted in my case. A key of type Key would be more preferable I guess. Thank you again for your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants