我想创建一个带有标签的应用程序以获取用户输入.问题是,不同的选项卡获得不同的输入,但是我必须收集数据库的输入.我的主意是,主要的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)发送回主支架
发布评论