代码之家  ›  专栏  ›  技术社区  ›  Natesh bhat

在颤振中向计算函数发送多个参数

  •  2
  • Natesh bhat  · 技术社区  · 7 年前

    void _blockPressHandler(int row, int col) async {
    //    Called when user clicks any block on the sudoku board . row and col are the corresponding row and col values ;
        setState(() {
          widget.selCol = col;
          }
        });
    
        bool boardSolvable;
        boardSolvable = await compute(SudokuAlgorithm.isBoardInSudoku , widget.board , widget.size) ;
    
      }
    

    isBoardInSudoku 是SudokuAlgorithm类的静态方法。它存在于另一个文件中。写上面的代码,告诉我

    error: The argument type '(List<List<int>>, int) → bool' can't be assigned to the parameter type '(List<List<int>>) → bool'. (argument_type_not_assignable at [just_sudoku] lib/sudoku/SudokuPage.dart:161)

    我怎么解决这个问题?在不将SudokuAlgorithm类的方法从其文件中取出的情况下,可以这样做吗?如何向计算函数发送多个参数?

    static bool isBoardInSudoku(List<List<int>>board , int size ){ } 是我的isBoardInSudoku函数。

    1 回复  |  直到 6 年前
        1
  •  8
  •   Günter Zöchbauer    7 年前

    只要把参数放在一张地图上,然后传过来。

    无法将多个参数传递给 compute 因为这是一个方便的函数来启动隔离,它也只允许一个参数。

        2
  •  3
  •   live-love    6 年前

    Map map = Map();
    map['val1'] = val1;
    map['val2'] = val2;
    Future future1 = compute(longOp, map);
    
    
    Future<double> longOp(map) async {
      var val1 = map['val1'];
      var val2 = map['val2'];
       ...
    }