cdoxs_location_package 0.0.1
cdoxs_location_package: ^0.0.1 copied to clipboard
A Flutter package to get user location with offline support.
π location_package #
A Flutter package for obtaining the user's current location with support for offline fallback using the last known position. Built using geolocator and permission_handler.
β¨ Features #
- Get current location with configurable accuracy.
- Fallback to last known location (offline support).
- Automatic permission handling.
- Easily extendable for location-based features.
π Installation #
Add the following to your pubspec.yaml:
dependencies:
location_package: ^0.0.1
Then run:
flutter pub get
βοΈ Usage
import 'package:location_package/location_package.dart';
void getUserLocation() async {
final locationService = LocationService(
accuracy: LocationAccuracy.high,
askPermissions: true,
useFallback: true,
);
final location = await locationService.getLocation();
if (location != null) {
print('Latitude: ${location.latitude}');
print('Longitude: ${location.longitude}');
} else {
print('Failed to retrieve location.');
}
}
Platform Configuration
π§ Android Configuration
Add the following permissions to your appβs AndroidManifest.xml file located at:
android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
For Android 10+ support, update your android/app/build.gradle:
defaultConfig {
minSdkVersion 21
// ...
}
Also, ensure your compileSdkVersion and targetSdkVersion are at least 33.
π iOS Configuration
In your ios/Runner/Info.plist file, add:
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to your location.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs continuous location access in the background.</string>
π¦ API
LocationService constructor:
LocationService({
LocationAccuracy accuracy = LocationAccuracy.high,
bool askPermissions = true,
bool useFallback = true,
});
Methods:
Future<Position?> getLocation() β Returns best available location with fallback.
Future<Position?> getCurrentLocation() β Returns current location if permissions are granted.
Future<Position?> getLastKnownLocation() β Returns the cached last location (if any).
π‘οΈ License
This project is licensed under the MIT License.
π¬ Contributions & Issues
Feel free to open issues or submit pull requests. Contributions are welcome!