loadData static method

Future<void> loadData()

Implementation

static Future<void> loadData() async {
  // Check if we're in a test environment
  final isTest = Platform.environment.containsKey('FLUTTER_TEST');

  if (isTest) {
    // Load from file system for tests
    provinces ??= json.decode(
      await File('lib/data/provinces.json').readAsString(),
    );

    municipalities ??= json.decode(
      await File('lib/data/municipalities.json').readAsString(),
    );

    barangays ??= json.decode(
      await File('lib/data/barangays.json').readAsString(),
    );
  } else {
    // Load from assets for runtime
    provinces ??= json.decode(
      await rootBundle
          .loadString('packages/ph_address_finder/data/provinces.json'),
    );

    municipalities ??= json.decode(
      await rootBundle
          .loadString('packages/ph_address_finder/data/municipalities.json'),
    );

    barangays ??= json.decode(
      await rootBundle
          .loadString('packages/ph_address_finder/data/barangays.json'),
    );
  }
}