Flutter 颤振:小部件不是类型为';障碍物优先尺寸边缘';
我正在尝试将AppBar存储在一个变量中,以便使用多个位置 我的main.dart文件包含-Flutter 颤振:小部件不是类型为';障碍物优先尺寸边缘';,flutter,dart,widget,flutter-layout,flutter-dependencies,Flutter,Dart,Widget,Flutter Layout,Flutter Dependencies,我正在尝试将AppBar存储在一个变量中,以便使用多个位置 我的main.dart文件包含- final PreferredSizeWidget appBar = NavigationAppBar(_actionCall) class NavigationAppBar extends StatelessWidget with PreferredSizeWidget { final Function actionCall; NavigationAppBar(this.actionCal
final PreferredSizeWidget appBar = NavigationAppBar(_actionCall)
class NavigationAppBar extends StatelessWidget with PreferredSizeWidget {
final Function actionCall;
NavigationAppBar(this.actionCall);
@override
Widget build(BuildContext context) {
return Platform.isIOS ?
CupertinoNavigationBar(
middle: Text(
'ABC'
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
child: Icon(CupertinoIcons.add),
onTap: () => actionCall,
)
],
),
) :
AppBar(
title: Text('ABC'),
centerTitle: false,
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: () => actionCall,
)
],
);
}
@override
Size get preferredSize => Size.fromHeight(kToolbarHeight);
}
导航应用程序栏包含-
final PreferredSizeWidget appBar = NavigationAppBar(_actionCall)
class NavigationAppBar extends StatelessWidget with PreferredSizeWidget {
final Function actionCall;
NavigationAppBar(this.actionCall);
@override
Widget build(BuildContext context) {
return Platform.isIOS ?
CupertinoNavigationBar(
middle: Text(
'ABC'
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
child: Icon(CupertinoIcons.add),
onTap: () => actionCall,
)
],
),
) :
AppBar(
title: Text('ABC'),
centerTitle: false,
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: () => actionCall,
)
],
);
}
@override
Size get preferredSize => Size.fromHeight(kToolbarHeight);
}
我如何解决这个问题?非常感谢您的帮助。您是否尝试过在代码中所有适用的位置用PreferredSizeWidget替换NavigationAppBar?这对我有帮助 我的问题有一点不同,因为我必须用PreferredSizeWidget替换AppBar(而不是NavigationAppBar)
这可能与最新颤振版本中的某些更改有关。您是否尝试在代码中的所有适用位置用PreferredSizeWidget替换NavigationAppBar?这对我有帮助 我的问题有一点不同,因为我必须用PreferredSizeWidget替换AppBar(而不是NavigationAppBar) 这可能与最新颤振版本中的某些更改有关