location_reader
location_reader is a Flutter package designed to simplify the process of retrieving and handling location-related data. It supports features such as obtaining the current location, converting coordinates to city names or country codes, managing location permissions, and performing nearby location queries with GeoFirePoint and Firebase.
Features
- π Get current location using
Geolocator - ποΈ Convert latitude and longitude to city name and country code using
geocoding - π Retrieve
GeoFirePointobjects for use in Firebase - π‘ Nearby location query support via
geoflutterfire2 - π Seamless location permission handling
- π‘ Clean architecture with services, repositories, use cases, and cubits
Installation
Add the following to your pubspec.yaml:
dependencies:
location_reader: ^<latest_version>
Then run:
flutter pub get
Getting Started
1. Register Dependencies
Ensure you call the DI registration method before using the services:
registerLocationServiceGetItDi();
2. Use Cases
You can access location-related use cases like this:
final getCurrentLocation = sl<GetCurrentLocation>();
final location = await getCurrentLocation();
3. UI Integration
Use LocationPicker and CountryCodeLoader widgets:
LocationPicker(
onTap: () => // pick location logic,
)
CountryCodeLoader(
page: (code) => Text("Country: $code"),
)
Dependencies
geolocatorgeocodinggeoflutterfire2flutter_blocget_itdartzjson_serializable
Example Use Cases
GetCityNameGetCountryCodeGetCurrentLocation
All of these use cases internally handle permissions, errors, and edge cases.
JSON Support
The LocationModel class supports JSON serialization using json_serializable.
Error Handling
Utilizes Either from dartz and custom IFailure/LocationError for structured error handling.
Contributing
Feel free to open issues and contribute pull requests for enhancements or bug fixes.
License
MIT License. See LICENSE file for details.
Libraries
- config/bloc_provider/register_location_bloc_provider
- config/di/register_location_service_get_it_di
- data/data_sources/address_service_impl
- data/data_sources/city_name_service_impl
- data/data_sources/country_code_service_impl
- data/data_sources/geo_fire_point_converter_impl
- data/data_sources/i_location_services/i_address_service
- data/data_sources/i_location_services/i_city_name_service
- data/data_sources/i_location_services/i_country_code_service
- data/data_sources/i_location_services/i_geo_fire_point_converter
- data/data_sources/i_location_services/i_location_crud_service
- data/data_sources/i_location_services/i_location_permission_manager
- data/data_sources/i_location_services/i_location_service_geo_fire_point_provider
- data/data_sources/i_location_services/i_location_service_geo_locator_provider
- data/data_sources/i_location_services/i_nearby_location_service
- data/data_sources/location_firestore_crud_service_impl
- data/data_sources/location_permission_manager_geo_locator_provider_impl
- data/data_sources/location_service_geo_fire_point_provider_impl
- data/data_sources/location_service_geo_locator_provider_impl
- data/data_sources/nearby_location_geofire_service_impl
- data/geofence_searvice
- data/model/location_model
- data/repositories/city_name_repository_impl
- data/repositories/country_code_repository_impl
- data/repositories/current_location_repository_impl
- data/repositories/geo_location_repository
- domain/entities/location_entity
- domain/i_repository/i_city_name_repository
- domain/i_repository/i_country_code_repository
- domain/i_repository/i_current_location_repository
- domain/i_repository/i_location_repository
- domain/usecases/get_city_name
- domain/usecases/get_country_code
- domain/usecases/get_current_location
- location_reader
- utils/convert_geo_fire_point
- utils/json_geo_point_converter_utils
- view_model/city_name_cubit/city_name_cubit
- view_model/city_name_cubit/city_name_state
- view_model/country_code_cubit/country_code_cubit
- view_model/country_code_cubit/country_code_state
- view_model/location_picker_cubit/location_picker_cubit
- views/widgets/city_name_builder
- views/widgets/country_code_loader
- views/widgets/location_picker