小编Md *_*har的帖子

Dart:根据条件将列表拆分为两个子列表

有没有办法根据如下条件在 dart 中拆分列表:

[1, 2, 3, 4, 5, 6, 7, 8] (A sample list)

After splitting it based on i % 2 == 0 condition, 
it would generate the following two lists:
1) [1, 3, 5, 7]
2) [2, 4, 6, 8]
Run Code Online (Sandbox Code Playgroud)

我知道我可以简单地编写一个循环来遍历所有元素并检查创建两个子列表的条件。但是 Dart 中有没有更短的函数方式呢?提前致谢!

list dart

7
推荐指数
2
解决办法
4615
查看次数

针对 Android api 版本 30 的应用程序的 Flutter 相机包权限

我最近将我的一个 flutter 应用程序的目标 sdk 升级到了 30。之后,拍照就不起作用了。它显示了此链接中提到的错误。

PlatformException(no_available_camera,没有可用于拍照的相机。,null)。

这与 android 11 中的包可见性更改有关。现在第一个链接中有一个解决方案,通过在清单文件中添加以下行来添加查询设备中安装的所有包的权限。

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
Run Code Online (Sandbox Code Playgroud)

这对我有用。但query_all_packages 的文档说明如下:

In the vast majority of cases, however, it's possible to fulfill your app's use cases by 
interacting with the set of apps that are visible automatically and by declaring the other 
apps that your app needs to access in your manifest file. To respect user privacy, your app 
should request the smallest amount of package visibility necessary in order for …
Run Code Online (Sandbox Code Playgroud)

android user-permissions flutter android-11

3
推荐指数
1
解决办法
2267
查看次数

如何将数组中的随机数分配给值?

我有一个数组的问题,并将它们分配给像float这样的值.这是我的代码

System.out.print("Please enter the number of iteration: ");
    Scanner scn = new Scanner(System.in);
    int inumber = scn.nextInt(); // i get the iteration number

        Random rnd = new Random();
        float x = -10 + rnd.nextFloat() * 20; // i created random number between 10 and -10
        System.out.println("My x = " +x);

            float[] xarray = new float[4]; // created my test array
            Random arrayrnd = new Random();


        for (int i=0;i<inumber;i++) { // created a for loop with that number

            for (int j …
Run Code Online (Sandbox Code Playgroud)

java arrays random loops

-3
推荐指数
1
解决办法
98
查看次数

标签 统计

android ×1

android-11 ×1

arrays ×1

dart ×1

flutter ×1

java ×1

list ×1

loops ×1

random ×1

user-permissions ×1