【发布时间】:2021-06-21 10:46:07
【问题描述】:
我创建了一个可重用的 appBar 类并在我想使用的任何地方调用它 这是代码
class MyAppBar extends AppBar {
MyAppBar({Key key,Widget title})
:super(key:key ,title:title,actions: <Widget>[
InkWell(
onTap: () {
Profile();
},
child: Padding(
padding: const EdgeInsets.all(14),
child: ClipOval(
child: Image.network(
'https://googleflutter.com/sample_image.jpg',
),
),
),
),
]
);}
当点击图片时,它不会重定向到个人资料屏幕。 我也用过这个
Navigator.push(context, MaterialPageRoute(builder: (context)=>Profile()));
但它在上下文上给了我错误,因为它没有定义。
如果有人知道如何解决它,请提供帮助。
【问题讨论】:
-
你试过通知父类吗?您可以将函数传递给 appbar 类,然后在点击时,它将调用父类上的函数。此功能导航到其他页面。您还可以查看无上下文导航文章medium.com/flutter-community/… 如果其中任何一项有帮助,请通知我
-
可以用您的答案编辑我的代码吗?我不知道该怎么做