扑打,选项卡和访问单选项卡窗口小部件状态

发布于 2025-01-31 11:49:24 字数 295 浏览 2 评论 0原文

我有一个动态具有n个标签内容小部件的选项卡。因此,有带标签标头的小部件页面和一个foreach选项卡内容。现在,我需要在每个选项卡中搜索的主选项卡中实现搜索,并在每个选项卡中搜索搜索,如果找到了搜索字符串,请更改当前选项卡并突出显示资助的字符串。为此,我需要从主选项卡页面访问每个选项卡的内容状态,我尝试创建一个GlobalKeys的列表,每个选项卡内容窗口小部件都有一个,但只有第一个键具有第一个选项卡的状态,而其他键则具有所有状态成员未初始化。我不知道为什么。

有一种解决此问题的方法,或者最好避免每个选项卡内容的一个小部件并将全部放入主选项卡页面中? 谢谢

I have a tab that dynamically has n tabs content widgets. So there is widget page with tab header and one widget foreach tab content. Now I need to implement search in main tab which search in every tab content widget and if searched string is found change the current tab and highlight the string funded. To do this I need to access every tab content state from main tab page, I try to create a list of GlobalKeys, one for each tab content widget but only the first key have the state of first tab content widget, other keys have all state members not initialized. I don't know why.

There is a way to solve this or it is better to avoid one widget for each tab content and put all in main tab page?
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So尛奶瓶 2025-02-07 11:49:24

这里的代码。我指定n个选项卡是状态窗口小部件的类型相同,但填充了不同的数据。

选项卡的全局键列表的定义:

List<GlobalObjectKey> tabKeys = List.empty(growable: true);

以下代码构建单选项卡窗口小部件,将创建并分配给programDayWidget,该键是statefull with,我要访问其状态的状态:

Widget buildTabView(BuildContext context, Program p) {
programDayWidgets.clear();
List<Widget> tabs = [];

tabKeys.clear();

for (int i = 0; i < p.days.length; i++)
{
  var k = GlobalObjectKey("tab" + i.toString());
  tabKeys.add(k);

  var w = ProgramDayWidget(event: event, programDay: p.days[i], key: k);

  programDayWidgets.add(w);
  tabs.add(w);
}

return Expanded(
  flex: 1,
  child: TabBarView(
    children: tabs,
    controller: _tabController,
  ),
)};

每当setState重建选项卡时,都会清除TabKeys呼叫。
如果我在SetState TabKeys具有3个键(像选项卡一样正确)之后对此功能进行断点,但是只有第一个密钥才能初始化第一个选项卡的CurrentState成员,而在其他两个键Currentstale中,像键的其他成员一样,则是NULL 。

谢谢

Here the code. I specify that the n tabs are the same type of statefull widget but populated with different data.

Definition of list of global key of tabs:

List<GlobalObjectKey> tabKeys = List.empty(growable: true);

The following code build single tab page widget, the key is created and assigned to the ProgramDayWidget that is the statefull widged whose status I want to access:

Widget buildTabView(BuildContext context, Program p) {
programDayWidgets.clear();
List<Widget> tabs = [];

tabKeys.clear();

for (int i = 0; i < p.days.length; i++)
{
  var k = GlobalObjectKey("tab" + i.toString());
  tabKeys.add(k);

  var w = ProgramDayWidget(event: event, programDay: p.days[i], key: k);

  programDayWidgets.add(w);
  tabs.add(w);
}

return Expanded(
  flex: 1,
  child: TabBarView(
    children: tabs,
    controller: _tabController,
  ),
)};

tabKeys is cleared every time the tab is rebuild for SetState calls.
If I put a breakpoint on this function after a SetState tabKeys has 3 keys (correct like tabs) but only the first key has the currentState member initialized for the first tab, in others two keys currentStale, like other members of the key, is null.

Thank you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文