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

Implement useTabControllerList for List<TabController> #406

Closed
dodatw opened this issue Dec 22, 2023 · 6 comments
Closed

Implement useTabControllerList for List<TabController> #406

dodatw opened this issue Dec 22, 2023 · 6 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@dodatw
Copy link

dodatw commented Dec 22, 2023

I have a requirement. There are an indefinite number of Tabs on my UI, so I need to have an indefinite number of TabControllers. How do I implement in HookWidget ?

It seem bad idea that add useTabController in a for loop.

List<TabController> subControllers;
for(...) {
   subControllers.add(useTabController(initialLength: length));
}

I try to use useRef and handle TabController myself, but it cannot set vsync in hookwidget.

final subControllers = useRef<List<TabController>>([]);
for(...) {
   subControllers.value.add(TabController(length: lenght, vsync: xxx))
}

is there any good idea ?

@rrousselGit
Copy link
Owner

That would be too specific. I don't think this is a good fit for the core package.

In any cases, chances are you want to use useTabController, but move the hook inside your tab widget. This way no matter how many tabs you have, they would all have a unique controller.

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Dec 22, 2023
@dodatw
Copy link
Author

dodatw commented Dec 23, 2023

We need to control each tab from parent, so we need to create tabcontroller at outside.
For Other controller, (ex, scrollController), I can use useRef + list view handle ourself.
But for TabController, it need TickerProvider, but useTickerProvider can only assign in one of TabController.

Another solution, is it possiable provide hook for List ?

@dodatw
Copy link
Author

dodatw commented Dec 23, 2023

I think my question should be how to handle indefinite number of TickerProvider in Hook. In useSingleTickerProvider, it say

      throw FlutterError(
          '${context.widget.runtimeType} attempted to use a useSingleTickerProvider multiple times.\n'
          'A SingleTickerProviderStateMixin can only be used as a TickerProvider once. '
          'If you need multiple Ticker, consider using useSingleTickerProvider multiple times '
          'to create as many Tickers as needed.');

How it work in indefinite case ?

@rrousselGit
Copy link
Owner

SingleTickerProviders cannot be passed to different objects.
Use a different ticker provider instead. To do so, call useSingleTickerProvider multiple times.

@dodatw
Copy link
Author

dodatw commented Dec 25, 2023

The problem is I don't know how many useSingleTickerProvider I need when coding.
It is runtime number.

Is that mean I cannot use hookWidget at this case ?

@rrousselGit
Copy link
Owner

I have no plan for adding a useTabControllerList, so closing.

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

No branches or pull requests

2 participants