android - 如何在flutter中将类函数传递给另一个类中的小部件
问题描述
我有 3 页 1,2,3 我想通过单击第二页中实现第一页功能的按钮到达第三页
那么如何将函数传递到第二页
所以这是具有功能的类
class SharedPage extends StatefulWidget {
_SharedPageState createState() => _SharedPageState();
}
class _SharedPageState extends State<SharedPage> {
String _information = '';
void updateInformation(String information) {
setState(() => _information = information);
}
void moveToSecondPage() async {
final information = await Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return AddShared(); /// this is the page that i want to reach
}),
);
updateInformation(information);
}
这是我想将函数传递给的类
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
var add = [
FlatButton(
shape: CircleBorder(),
child: Icon(
Icons.add,
color: Colors.red,
size: 30,
),
onPressed: () {
/// i want to implement the MoveToSecondScreen here
},
),
];
解决方案
推荐阅读
- python - python中关键字值参数的目的?
- web.config-transform - Visual Studio ASP XML web.config 转换换行
- google-sheets - 将索引 XAO 价格导入谷歌表
- python - 如何自定义 python 记录器行为?
- sql - RIGHT JOIN 是使用此查询的方式吗?
- azure - 为什么我的 Bing 认知服务请求返回 401?
- cmake - 带有 CMake 的 STM32 项目
- c# - 编译器错误 MT2002:当 IOS 应用程序 (Xamarin) 引用 VB.NET Windows 窗体项目中的类时
- python - Chrome 的源 HTML 与 Internet Explorer 不同?
- ruby-on-rails - 升级到 macOS Mojave 后,如何找到我的 Rails 应用程序在客户端第一次请求(pg.rb 分段错误)后崩溃的来源?