fromMap static method
Implementation
static IsolateCommand fromMap(Map map) {
final command = map['command'] as String?;
switch (command) {
case 'set_surah_reference':
final rawRules = map['wordRules'] as List?;
final List<List<WordTajweedRule>>? wordRules = rawRules?.map((l) {
return (l as List)
.map((r) => WordTajweedRule.fromMap(r as Map))
.toList();
}).toList();
return SetSurahReferenceCommand(
fullPhonemes: map['phonemes'] as String,
boundaries: (map['boundaries'] as List).cast<int>(),
surahNumber: map['surahNumber'] as int? ?? 0,
isTajweed: map['isTajweed'] as bool? ?? false,
forceClear: map['forceClear'] as bool? ?? false,
startGlobalWord: map['startGlobalWord'] as int? ?? 0,
wordRules: wordRules,
);
case 'sync_stream':
return SyncStreamCommand(
asrText:
map['text'] as String? ??
(map['tokens'] as List?)?.join('') ??
'',
timestamps: (map['timestamps'] as List?)
?.map((e) => (e as num?)?.toDouble() ?? 0.0)
.toList() ??
const [],
isNewSegment: map['is_new_segment'] as bool? ?? false,
ayahNumber: map['ayah_number'] as int? ?? 0,
);
case 'jump_to_word':
return JumpToWordCommand(
globalWordIndex: map['global_word_index'] as int? ?? 0,
);
case 'set_tajweed_mode':
return SetTajweedModeCommand(
isTajweed: map['is_tajweed'] as bool? ?? false,
);
case 'update_config':
return UpdateTrackerConfigCommand(
config: TrackerConfig(
recitationSpeed:
RecitationSpeed.fromName(map['recitationSpeed'] as String?),
matchingStrictness:
MatchingStrictness.fromName(map['matchingStrictness'] as String?),
enableEarlyMatching: map['enableEarlyMatching'] as bool? ?? true,
enableAutoReanchor: map['enableAutoReanchor'] as bool? ?? false,
reanchorStallThreshold: map['reanchorStallThreshold'] as int? ?? 24,
),
);
case 'stop':
return const StopIsolateCommand();
default:
throw ArgumentError('Unknown IsolateCommand: $command');
}
}