简体   繁体   English

如何将 function 传递给较低的小部件

[英]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.

相关问题 如何将 function 作为小部件中的参数传递? - How to pass a function as a parameter in widget? 如何将小部件作为参数传递给函数 - How to pass the widget as a parameter to the function 如何将小部件自己的数据传递给函数 - How to pass widget's own data to a function Flutter 如何将异步函数传递给另一个小部件? - Flutter how to pass async function to another widget? 如何将 void 函数从同一个小部件传递给另一个小部件,然后将相同的 void 函数从另一个小部件返回到同一个小部件中颤振 - how to pass the void function from same widget to another widget and then return the same void function from another widget to same widget in flutter 如何正确地将值传递给 Flutter 中任何小部件的事件处理函数? - How to properly pass values to an event handler function of any widget in Flutter? 将返回未来的 Function 传递给 Widget - Pass to Widget a Function that returns a future 如何将 Navigator 或 Void 函数作为参数传递给 ListTile Widget -Flutter - How to pass Navigator or Void function as a parameter to a ListTile Widget -Flutter 如何在颤动中将函数传递给可重用的文本输入小部件? - How to pass Function to a reusable Text Input widget in flutter? 如何将小部件的索引值传递给父小部件 - how to pass index value of a widget to parent widget
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM