loadSurahJsonList method

Future<List?> loadSurahJsonList(
  1. int surahNumber
)

Implementation

Future<List<dynamic>?> loadSurahJsonList(int surahNumber) async {
  if (!isEnabled()) return null;

  if (kIsWeb) {
    final url =
        '$webBaseUrl/sura_${surahNumber.toString().padLeft(3, '0')}.json';
    final dio = Dio()
      ..options.connectTimeout = const Duration(seconds: 20)
      ..options.receiveTimeout = const Duration(seconds: 20);

    final response = await dio.get<String>(
      url,
      options: Options(responseType: ResponseType.plain),
    );
    final text = response.data;
    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;
}