Dart - 如何连接字符串和我的整数

dbm*_*211 6 string integer concatenation dart flutter

如何连接字符串和 int 行: print('Computer is moving to ' + (i + 1));print("Computer is moving to " + (i + 1));

我无法弄清楚,因为错误一直显示“参数类型‘int’无法分配给参数类型‘String’

void getComputerMove() {
    int move;

    // First see if there's a move O can make to win
    for (int i = 0; i < boardSize; i++) {
      if (_mBoard[i] != humanPlayer && _mBoard[i] != computerPlayer) {
        String curr = _mBoard[i];
        _mBoard[i] = computerPlayer;
        if (checkWinner() == 3) {
          print('Computer is moving to ' + (i + 1));
          return;
        } else
          _mBoard[i] = curr;
      }
    }

    // See if there's a move O can make to block X from winning
    for (int i = 0; i < boardSize; i++) {
      if (_mBoard[i] != humanPlayer && _mBoard[i] != computerPlayer) {
        String curr = _mBoard[i]; // Save the current number
        _mBoard[i] = humanPlayer;
        if (checkWinner() == 2) {
          _mBoard[i] = computerPlayer;
          print("Computer is moving to " + (i + 1));
          return;
        } else
          _mBoard[i] = curr;
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

hnn*_*lch 15

使用字符串插值:

print("Computer is moving to ${i + 1}"); 
Run Code Online (Sandbox Code Playgroud)

或者直接调用 toString():

print("Computer is moving to " + (i + 1).toString()); 
Run Code Online (Sandbox Code Playgroud)