[英]How to pass a function to lower widget
child: DismissiblePage(
direction: DismissDirection.down,
onDismiss: () => Navigator.of(context).pop(),
child: InstagramStorySwipe(
initialPage: index,
children: List.generate(
snapshot.data?.data?.data?.user?.feedReelsTray
?.edgeReelsTrayToReel?.edges?.length,
(index) => ViewStoryScreen(
// changePage: ,
index: index,
edges: snapshot.data.data.data.user.feedReelsTray
.edgeReelsTrayToReel.edges,
),
),
),
),
Here i have a method in InstagramStorySwipe which i need to call with the ViewStoryScreen在这里,我在 InstagramStorySwipe 中有一个方法,我需要使用 ViewStoryScreen 调用它
Edit: code also the whole thing is inside another class so i cant call InstagramSwipes method编辑:整个代码也在另一个 class 里面,所以我不能调用 InstagramSwipes 方法
Assuming the "method in InstagramStorySwipe" is called myMethod
, you can add a parameter to the constructor of ViewStoryScreen
like so:假设“InstagramStorySwipe 中的方法”被称为
myMethod
,您可以像这样向ViewStoryScreen
的构造函数添加一个参数:
class ViewStoryScreen extends StatelessWidget { // or StatefulWidget
ViewStoryScreen({
this.changePage,
this.index,
this.edges,
this.myMethod,
});
/// The method passed by the parent
final void Function() myMethod; // Change the signature of the function depending on myMethod
final String changePage;
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.