flutter-基于选项卡主体中内容长度的选项卡名称中的动态字符串
大家好,我正在尝试更新选项卡名称,其中包含在选项卡内容中的列表中的项目数。该列表在选项卡内容组件中获取。如何将列表长度变量传递给标题标题?
// PARENT WIDGET
class EventsScreen extends StatefulWidget {
const EventsScreen({Key? key}) : super(key: key);
@override
State<EventsScreen> createState() => _EventsScreenState();
}
class _EventsScreenState extends State<EventsScreen> {
@override
Widget build(BuildContext context) {
return Parent(
child: TabbedHeader(
tabTitles: [
'Žiadosti (HERE I WANT TO ADD LENGTH OF REQUESTS LIST)'
],
title: 'Udalosti',
tabContents: [
EventRequestTab() // CHILD COMPONENT WITH LIST OF REQUESTS
],
),
);
}
}
// CHILD WIDGET WITH REQUESTS LIST
class EventRequestTab extends StatefulWidget {
const EventRequestTab({Key? key, this.requests}) : super(key: key);
@override
State<EventRequestTab> createState() => _EventRequestState();
}
class _EventRequestState extends State<EventRequestTab> {
late EventService _eventService;
late List<EventRequest>? requests;
@override
void initState() {
super.initState();
_eventService = EventService();
requests = // FETCHING LIST OF REQUESTS
}
} ... build method etc ....
在Initstate中的儿童小部件中,我正在获取后来在ListView中显示的请求列表。但是我不知道如何将被提取列表的长度传递给TabTitles属性。 TabBedheader是我的Tabbar小部件的自定义包装器。
Hi all I am trying to update Tab name with the number of items in lists stored in tab content. The list is fetched in tab content component. How can I pass list length variable to tab title ?
// PARENT WIDGET
class EventsScreen extends StatefulWidget {
const EventsScreen({Key? key}) : super(key: key);
@override
State<EventsScreen> createState() => _EventsScreenState();
}
class _EventsScreenState extends State<EventsScreen> {
@override
Widget build(BuildContext context) {
return Parent(
child: TabbedHeader(
tabTitles: [
'Žiadosti (HERE I WANT TO ADD LENGTH OF REQUESTS LIST)'
],
title: 'Udalosti',
tabContents: [
EventRequestTab() // CHILD COMPONENT WITH LIST OF REQUESTS
],
),
);
}
}
// CHILD WIDGET WITH REQUESTS LIST
class EventRequestTab extends StatefulWidget {
const EventRequestTab({Key? key, this.requests}) : super(key: key);
@override
State<EventRequestTab> createState() => _EventRequestState();
}
class _EventRequestState extends State<EventRequestTab> {
late EventService _eventService;
late List<EventRequest>? requests;
@override
void initState() {
super.initState();
_eventService = EventService();
requests = // FETCHING LIST OF REQUESTS
}
} ... build method etc ....
In child widget in initState I am fetching list of requests which is later displayed in ListView. But I dont know how to pass length of fetched list to tabTitles property of TabbedHeader. TabbedHeader is my custom wrapper for TabBar widget.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过
eventRequestTab
的状态类中获取的列表,通过将回调传递到EventRequestTab
widtget中。此回调将返回以其参数获取的列表,在
eventsscreen
中,Tab名称已更新,并使用列表的长度更新此处,此处是您的代码的更新:
You can pass the list fetched in the
initState
of yourEventRequestTab
's state class by passing a callback into theEventRequestTab
widget.This callback will return the list fetched as its parameter and in the
EventsScreen
, the tab name is updated with the length of the listHere's an update to your code: