blob: 9ee68ac4b8b5a8071f12135b65a26ae90ca6d4a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import 'dart:io';
import 'package:flutter_ics_homescreen/export.dart';
import 'package:yaml/yaml.dart';
class RadioPreset {
final int frequency;
final String name;
RadioPreset({required this.frequency, required this.name});
}
class RadioPresets {
final List<RadioPreset> fmPresets;
RadioPresets({required this.fmPresets});
}
final radioPresetsProvider = Provider((ref) {
final presetsFilename = ref.read(appConfigProvider).radioConfig.presets;
if (presetsFilename.isEmpty) {
return RadioPresets(fmPresets: []);
}
try {
print("Reading radio presets $presetsFilename");
var presetsFile = File(presetsFilename);
String content = presetsFile.readAsStringSync();
final dynamic yamlMap = loadYaml(content);
List<RadioPreset> presets = [];
if (yamlMap.containsKey('fm')) {
dynamic list = yamlMap['fm'];
if (list is YamlList) {
for (var element in list) {
if ((element is YamlMap) &&
element.containsKey('frequency') &&
element.containsKey('name')) {
presets.add(RadioPreset(
frequency: element['frequency'].toInt(),
name: element['name'].toString()));
}
}
}
}
return RadioPresets(fmPresets: presets);
} catch (_) {
debugPrint("Exception reading presets!");
return RadioPresets(fmPresets: []);
}
});
|