loadSurahJsonList method
Implementation
Future<List<dynamic>?> loadSurahJsonList(int surahNumber) async {
if (!isEnabled()) return null;
if (kIsWeb) {
final fileName = 'sura_${surahNumber.toString().padLeft(3, '0')}.json';
final urls = <String>[
'$webBaseUrl/$fileName',
if (webBaseUrlGitLab != null) '$webBaseUrlGitLab/$fileName',
];
final dio = Dio()
..options.connectTimeout = const Duration(seconds: 20)
..options.receiveTimeout = const Duration(seconds: 20);
String? text;
for (final url in urls) {
try {
final response = await dio.get<String>(
url,
options: Options(responseType: ResponseType.plain),
);
text = response.data;
if (text != null && text.isNotEmpty) break;
} catch (_) {
continue;
}
}
if (text == null || text.isEmpty) return null;
final decoded = jsonDecode(text);
return decoded is List ? decoded : null;
}
await _ensureIndex();
final path = _filePathBySurah[surahNumber];
if (path == null) return null;
final text = await File(path).readAsString();
final decoded = jsonDecode(text);
return decoded is List ? decoded : null;
}