【发布时间】:2020-05-04 09:43:04
【问题描述】:
在我的主页.dart 中,我有这段代码。当有文本时,我想调用在页面 B 构建函数中声明的过滤函数。我怎样才能做到这一点?
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: _appBarTitle,
actions: <Widget>[
IconButton(
onPressed: () {
setState(() {
....
decoration: new InputDecoration(
onChanged: (value) {
// call filter function in pageB
},
);
....
}
【问题讨论】:
-
你试过了吗 -
PageB pageB = new pageB(); pageB.myFunction(); -
@Sukhi 是的,它说没有定义。
-
是公共功能吗?
-
@Sukhi 是的。我刚刚宣布它们为无效。
-
将pageA中的dart文件导入为“import pageb.dart”。您将能够访问pageB中的功能。这不是理想的方式,但应该有效。