Wasted 3 days on Isolate Packages and Flutter,
trying to solve the Channel Method Blocking problem.
Failed.
Then, i started to work on the same test with SwiftUI,
and give me the idea, of doing the same with Flutter.
It is a LOT of steps:
1. Flutter call a channel-method, pass list of filePath.(listOfString)
2.1 MacOS side
let listOfUrl : [URL] = listOfString.compactMap { URL.init(fileURLWithPath: $0) }
var tmpList : [PlaylistItem] = []
2.2 (do the followings inside a GCD GlobalQueue)
create list of playlistItem with metadata (Apple Class)
listOfUrl.forEach { (thisUrl) in
let pi = PlaylistItem.init(url: thisUrl)
pi.setMetaData()
pi.ContentIdx = 0
tmpList.append(pi)
}
2.3
ReGroup this list of PI by ArtistName
let dictionary = Dictionary(grouping: tmpList, by:
{ (element: PlaylistItem) in
return element.Artist
})
3. Now the stupid parts, convert it to JSON encodable object.(sorted)
// JsonCompObject, member Pl, is the JSON encodable
var artistPL : [JsonCompObject] = [] // artist and Pl
dictionary.forEach { (arg0) in
if (self?.isAbortPL ?? true) { return }
let (key, value) = arg0 // key is Artist, value is list of PlayListItem
var listOfCodableObjects : [Pl] = []
value.forEach
{ pi in
let jObj : Pl = Pl.init(fullPath: pi.FullPath, genre: pi.Genre, album:pi.Album, duration: pi.Duration, artist: pi.Artist,lyrics: pi.Lyrics,
title: pi.Title, contentIdx:pi.ContentIdx, fileName: pi.FileName, year: pi.Year)
listOfCodableObjects.append(jObj)
} // end value Loop
var artistPlaylist : JsonCompObject = JsonCompObject.init(pl: listOfCodableObjects, artist: key ?? "unknown" )
if artistPlaylist.pl!.count * 3
{
artistPlaylist.pl!.sort{ $0.title! * $1.title! }
}
artistPL.append(artistPlaylist)
} // end Dictionary Loop
4. Sort the JSON objects
artistPL.sort { ($0.artist ?? "" ) * ($1.artfist ?? "") }
5. Encode
let jData = try JSONEncoder().encode(artistPL)
self?.jString = String(decoding: jData, as: UTF8.self) // target return
6. Event Channel
self?.delegate?.relaySongJson(self?.jString ?? "")
7. last MainQueue, set Update Completion Flags.
--------------
Flutter Side
______________
A. event channel
void _onEvent(Object? event)
{
if (event == null || isDispose) return;
var mapDv = event as Map*dynamic, dynamic*?;
if (mapDv != null)
{
// sorted JSON string return
final strJson = mapDv["JsonString"] as String?;
if (strJson != null)
{
// Quick Type IO
dartPL = myArtistPlayListFromJson(strJson);
isGettingMetaData = false; // enable sort and shuffle Buttons
}
} // end mapDv not null
}
______________
Resources
MacOS 11.3
Xcode 12.5
AS 4.1.3
Flutter 2.3.0-1.0.pre.13
_____________
Appears the Swiftui LazyVStack
inside a scroller is NOT Lazy.
(indicated by DeInit)