【发布时间】:2021-11-11 02:20:50
【问题描述】:
我将Scaffold 的appBar 声明为超出范围的变量。
PreferredSizeWidget originAppBar = AppBar(
centerTitle: true,
backgroundColor: Colors.white,
title: ....
这允许我通过将originAppBar 分配给appBar: 来使用它。
appBar: originAppBar,
但是,我在originAppBar 中包含了以下代码。
Navigator.of(context).pushNamed(Profile.route);
这是一个需要BuildContext 且不在originAppBar 中的函数。
是否可以有一个带参数的 PreferredSizeWidget?像这样的 C#;
//C#
PreferredSizeWidget originAppBar = new PreferredSizeWidget(BuildContext context)
Widget build(BuildContext xontext){
....
appBar: originAppBar(context)
....
}
谢谢。
【问题讨论】:
标签: flutter dart flutter-web