Flutter 我可以用什么关键字替换final来生成appbar变量?
我已经创建了一个appbar函数,可以在需要创建appbar时调用它,但是在创建appbar之前,关键字final会使在appbar上的图标按钮中添加on Pressed功能变得困难。当按下图标按钮时,如何绕过此问题并使其改变状态Flutter 我可以用什么关键字替换final来生成appbar变量?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我已经创建了一个appbar函数,可以在需要创建appbar时调用它,但是在创建appbar之前,关键字final会使在appbar上的图标按钮中添加on Pressed功能变得困难。当按下图标按钮时,如何绕过此问题并使其改变状态 final appBar = AppBar( elevation: 2.0, title: Text( 'HestiaLets App', style: TextStyle(
final appBar = AppBar(
elevation: 2.0,
title: Text(
'HestiaLets App',
style: TextStyle(
color: Colors.black,
fontSize: 30.0,
),
),
centerTitle: true,
backgroundColor: Colors.transparent,
leading: IconButton(icon: Icon(Icons.search), onPressed: null),,
);
也许你应该描述你的实际问题,而不是寻找一个最好的猜测解决方案。添加onPressed方法有什么问题?为什么这个问题会连接到“final”这个词?为什么不把它变成一个小部件,并将回调函数传递给onpressed呢?