loadStates method

Future<List<StateModel>> loadStates({
  1. String assetPath = 'packages/location_picker_plus/assets/state.json',
})

Implementation

Future<List<StateModel>> loadStates({
  String assetPath = 'packages/location_picker_plus/assets/state.json',
}) async {
  if (_states != null) return _states!;

  try {
    final String data = await rootBundle.loadString(assetPath);
    final List<dynamic> jsonList = json.decode(data);
    _states = jsonList.map((json) => StateModel.fromJson(json)).toList();
    _buildStateSearchIndex();
    return _states!;
  } catch (e) {
    throw Exception('Failed to load states: $e');
  }
}