Android Studio失去与设备的连接

时间:2019-10-15 06:19:49

标签: flutter combinations

我遇到了一个问题,我正在运行此代码并获取数字的所有不同组合而无需重复。

它放在for循环中,其中有一个数字列表。

如果列表仅包含1个数字,则似乎不错。但是,当列表中有多个数字时,Android Studio将失去与设备的连接。

是因为我的应用程序做得太多吗?如果没有,我该如何解决?

List<String> rollNumberGenerator(String num) {
    List numberToBeRolled = num.split('');

    List<String> generatedRollList = [];

    String zero = numberToBeRolled[0];
    String one = numberToBeRolled[1];
    String two = numberToBeRolled[2];
    String three = numberToBeRolled[3];

    String rollNumber1 = '$zero$one$two$three';
    String rollNumber2 = '$zero$one$three$two';
    String rollNumber3 = '$zero$three$one$two';
    String rollNumber4 = '$three$zero$one$two';
    String rollNumber5 = '$three$zero$two$one';
    String rollNumber6 = '$zero$three$two$one';
    String rollNumber7 = '$zero$two$three$one';
    String rollNumber8 = '$zero$two$one$three';
    String rollNumber9 = '$two$zero$one$three';
    String rollNumber10 = '$two$zero$three$one';
    String rollNumber11 = '$two$three$zero$one';
    String rollNumber12 = '$three$two$zero$one';
    String rollNumber13 = '$three$two$one$zero';
    String rollNumber14 = '$two$three$one$zero';
    String rollNumber15 = '$two$one$three$zero';
    String rollNumber16 = '$two$one$zero$three';
    String rollNumber17 = '$one$two$zero$three';
    String rollNumber18 = '$one$two$three$zero';
    String rollNumber19 = '$one$three$two$zero';
    String rollNumber20 = '$three$one$two$zero';
    String rollNumber21 = '$three$one$zero$two';
    String rollNumber22 = '$one$three$zero$two';
    String rollNumber23 = '$one$zero$three$two';
    String rollNumber24 = '$one$zero$two$three';

    generatedRollList.add(rollNumber1);
    generatedRollList.add(rollNumber2);
    generatedRollList.add(rollNumber3);
    generatedRollList.add(rollNumber4);
    generatedRollList.add(rollNumber5);
    generatedRollList.add(rollNumber6);
    generatedRollList.add(rollNumber7);
    generatedRollList.add(rollNumber8);
    generatedRollList.add(rollNumber9);
    generatedRollList.add(rollNumber10);
    generatedRollList.add(rollNumber11);
    generatedRollList.add(rollNumber12);
    generatedRollList.add(rollNumber13);
    generatedRollList.add(rollNumber14);
    generatedRollList.add(rollNumber15);
    generatedRollList.add(rollNumber16);
    generatedRollList.add(rollNumber17);
    generatedRollList.add(rollNumber18);
    generatedRollList.add(rollNumber19);
    generatedRollList.add(rollNumber20);
    generatedRollList.add(rollNumber21);
    generatedRollList.add(rollNumber22);
    generatedRollList.add(rollNumber23);
    generatedRollList.add(rollNumber24);

    List<String> validGeneratedRollList = [];

    for (var numbers in generatedRollList) {
      bool present = false;
      present = validGeneratedRollList.contains(numbers);
      if (present == false) {
        validGeneratedRollList.add(numbers);
      }
    }
    return validGeneratedRollList;
  }

在此先感谢任何可以提供帮助的人!

0 个答案:

没有答案