0

它将以下内容打印到控制台

I/System.out: [{file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20181028-WA0004.mp3, file_name=AUD-20181028-WA0004.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200507-WA0009.mp3, file_name=AUD-20200507-WA0009.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200507-WA0012.mp3, file_name=AUD-20200507-WA0012.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20181028-WA0005.mp3, file_name=AUD-20181028-WA0005.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20180624-WA0001.mp3, file_name=AUD-20180624-WA0001.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200310-WA0005.mp3, file_name=AUD-20200310-WA0005.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20180904-WA0004.mp3, file_name=AUD-20180904-WA0004.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200507-WA0011.mp3, file_name=AUD-20200507-WA0011.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200507-WA0008.mp3, file_name=AUD-20200507-WA0008.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20180807-WA0017.mp3, file_name=AUD-20180807-WA0017.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20181029-WA0000.mp3, file_name=AUD-20181029-WA0000.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200507-WA0010.mp3, file_name=AUD-20200507-WA0010.mp3}]
I/flutter: [{file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20181028-WA0004.mp3, file_name=AUD-20181028-WA0004.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200507-WA0009.mp3, file_name=AUD-20200507-WA0009.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200507-WA0012.mp3, file_name=AUD-20200507-WA0012.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20181028-WA0005.mp3, file_name=AUD-20181028-WA0005.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20180624-WA0001.mp3, file_name=AUD-20180624-WA0001.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200310-WA0005.mp3, file_name=AUD-20200310-WA0005.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20180904-WA0004.mp3, file_name=AUD-20180904-WA0004.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/WhatsApp Audio/AUD-20200507-WA0011.mp3, file_name=AUD-20200507-WA0011.mp3}, {file_path=/storage/emulated/0/WhatsApp/Media/

第一行是在 MainActivity.kt 中使用 println() 打印的,第二行是在 Flutter 中使用 print() 打印的

我什至尝试使用 Kotlin 中的 songList.size 和 flutter 中的 songList.length 来获取列表的长度。它在 Kotlin 中显示 14 ,在 flutter 中显示 1464 。我知道的一件事是,即使我发送了 result.success(songsList),flutter 也没有获得整个列表。这是Kotlin和flutter的代码

val songsList = getSongsList(Environment.getExternalStorageDirectory().absolutePath)
                println(songsList)
                result.success(songsList.toString())

    private fun getSongsList(rootPath:String) : ArrayList<HashMap<String, String>> {
        val fileList: ArrayList<HashMap<String, String>> = ArrayList()

         try {
            val rootFolder = File(rootPath)
            val files: Array<File> = rootFolder.listFiles() 
            for (file in files) {
                if (file.isDirectory) {
                    fileList.addAll(getSongsList(file.absolutePath))
                } else if (file.name.endsWith(".mp3")) {
                    val song: HashMap<String, String> = HashMap()
                    song["file_path"] = file.absolutePath
                    song["file_name"] = file.name
                    fileList.add(song)
                }
            }
            return fileList
        } catch (e: Exception) {
            throw Error("failed to load data $e")
        }
    } 

  Future<List<Song>> _getSongsList() async {
    print("calling get songs list");
    final String songlist = await platform.invokeMethod("getSongsList");
    print(songlist);
    print(songlist.length);
    var parsed = json.decode(songlist);
     List<Song> sList = parsed.map<Song>((json)=> new Song.fromJson(json)).toList();
    print(sList.toString());
    return sList;
  }
4

0 回答 0