Flutter:将数据从TabBarView(StatefullWidgets)发送回主支架

编程入门 行业动态 更新时间:2024-10-28 14:33:25
本文介绍了Flutter:将数据从TabBarView(StatefullWidgets)发送回主支架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想创建一个带有标签的应用程序以获取用户输入.问题是,不同的选项卡获得不同的输入,但是我必须收集数据库的输入.我的主意是,主要的Scaffhold会收集所有Tabs的输入并将其写入数据库中!我的问题是,我不知道将数据从选项卡(另一个文件中的statefullWidget)发送到父类(Scaffold)还是从那里运行函数!

I want to create an App with Tabs to get the users input. The Problem is, that the different Tabs get different inputs, but i have to collect the inputs for the Database. My idea her was, that the main Scaffhold collects the inputs from all Tabs and write it in a database! My Problem is, that i dont know to send data from the tab (statefullWidget in an other file) to the parent class (Scaffold) or run a function from there!

请帮助我,抱歉我的英语不好!

Please help me and sorry for my bad english!

乔纳斯(Jonas)

推荐答案

您可以传递一个 Function ,该函数可以随时调用.

You can pass a Function that can be called whenever you want.

MamaBear班

MamaBear class

... class _MamaBear extends State<MamaBear> { void hungryBear(String babyBear) { print("$babyBear is hungry"); } @override Widget build(BuildContext context) { return Scaffold( body: Container( child: Column(children: <Widget>[ BabyBear( "Mark", (babyBear) { hungryBear(babyBear); }, )])));}

BabyBear班

BabyBear class

class BabyBear extends StatefulWidget { final String babyBearName; final Function onBearAction; BabyBear(this.babyBearName, this.onBearAction); @override _BabyBear createState() => _BabyBear(); } class _BabyBear extends State<BabyBear> { @override Widget build(BuildContext context) { return Card( child: RaisedButton( child: Text("Mama I'm hungry"), onPressed: () { widget.onBearAction(widget.babyBearName); }), ); }

}

更多推荐

Flutter:将数据从TabBarView(StatefullWidgets)发送回主支架

本文发布于:2023-11-11 11:15:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578273.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:支架   数据   Flutter   StatefullWidgets   TabBarView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!