Flutter 如何将数据从TabBarView父级传递到选项卡?
我有三个选项卡,它们将从TabView(控制选项卡的小部件)接收字符串 我的代码如下所示:Flutter 如何将数据从TabBarView父级传递到选项卡?,flutter,dart,Flutter,Dart,我有三个选项卡,它们将从TabView(控制选项卡的小部件)接收字符串 我的代码如下所示: body: TabBarView( children: [ FloatingActionButtonWidget(), videosListForTab(), // <-- want to send string to imagesListForTab(), // <-- want
body: TabBarView(
children: [
FloatingActionButtonWidget(),
videosListForTab(), // <-- want to send string to
imagesListForTab(), // <-- want to send string to
Icon(Icons.label),
],
)
body:TabBarView(
儿童:[
FloatingActionButtonWidget(),
videosListForTab(),//尝试将您的函数(我猜它是一个函数)更改为
List videosListForTab(字符串值){…}
列表imagesListForTab(字符串值){…}
更改选项卡小部件构造函数以接收参数。
例如:
class VideosListForTab extends StatelessWidget {
final String value;
// This way, when instantiating the Widget, you have to pass the String
VideosListForTab(this.value);
@override
Widget build(BuildContext context) {
// return your Widget here
return Container();
}
}
您可以通过以下方式创建小部件:
body: TabBarView(
children: [
FloatingActionButtonWidget(),
videosListForTab("parameter as you want"), // <-- want to send string to
imagesListForTab(), // <-- want to send string to
Icon(Icons.label),
],
)
body: TabBarView(
children: [
FloatingActionButtonWidget(),
videosListForTab(
value: "parameter as you want"
), // <-- want to send string to
imagesListForTab(), // <-- want to send string to
Icon(Icons.label),
],
)
您可以通过以下方式创建小部件:
body: TabBarView(
children: [
FloatingActionButtonWidget(),
videosListForTab("parameter as you want"), // <-- want to send string to
imagesListForTab(), // <-- want to send string to
Icon(Icons.label),
],
)
body: TabBarView(
children: [
FloatingActionButtonWidget(),
videosListForTab(
value: "parameter as you want"
), // <-- want to send string to
imagesListForTab(), // <-- want to send string to
Icon(Icons.label),
],
)
body:TabBarView(
儿童:[
FloatingActionButtonWidget(),
录像带(
值:“根据需要设置参数”
),//我会试试,然后回来告诉你它是否有效。它非常有效……谢谢你不客气。请接受我的正确答案。谢谢。