我正在扩展 AppBar 小部件以创建我的自定义应用栏,如下所示。问题是我无法访问小部件中的“上下文”。问题 :-
- 这是扩展appbar的正确方法吗?
- 我怎样才能访问上下文?
class DashboardAppBar extends AppBar {
final String myTitle;
DashboardAppBar({Key key, @required this.myTitle})
: super(
key: key,
leading: IconButton(icon: Icon(Icons.dehaze_outlined), onPressed: () {}),
actions: [
FlatButton(
onPressed: () => Navigator.pop(context), //This line is the problem
child: Text(
'Logout',
style: TextStyle(fontSize: Sizes.dimen_20.sp),
),
),
IconButton(
icon: Icon(
Icons.notifications_none_outlined,
),
onPressed: () {})
],
title: Text(myTitle),
backgroundColor: Colors.transparent,
);
}