从另一个屏幕移回屏幕后,flutter调用函数

时间:2019-12-17 06:04:28

标签: flutter

从另一个屏幕移回一个屏幕后,如何在flutter中调用函数?

例如:

屏幕1

  Matrix prod;

  size_t inner = a->C;
  prod.R = a->R;
  prod.C = b->C;

  for( size_t r = 0; r < prod.R; ++r ) {
    for( size_t c = 0; c < prod.C; ++c ) {
      prod.index[r][c] = 0;
      for( size_t i = 0; i < inner; ++i ) {
        prod.index[r][c] += a->index[r][i] * b->index[i][c];
      }
    }
  }
  return prod;

Screen2

function1(){
}

2 个答案:

答案 0 :(得分:1)

很简单。

Navigator.push(context, MaterialPageRoute(builder: (context)=> SecondScreen())).then((_){
      // This method gets callback after your SecondScreen is popped from the stack or finished.
      function1();
    });

您还应该参考Flutter Navigation & Routing.

答案 1 :(得分:0)

这是解决方案!

第二屏幕

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <link rel="stylesheet" href="/main.css" />
  </head>
  <body>
    <button type="button" class="colorBtn">Press to change color</button>
    <script src="/script.js"></script>
  </body>
</html>

或者,如果您不想发回任何数据,则只能致电

Navigator.pop(context, [1]);

第一个屏幕

Navigator.pop(context);
相关问题