Skip to content

Instantly share code, notes, and snippets.

@khkred
Created April 27, 2024 00:16
Show Gist options
  • Save khkred/f71937072766332eae5241bebfc631f2 to your computer and use it in GitHub Desktop.
Save khkred/f71937072766332eae5241bebfc631f2 to your computer and use it in GitHub Desktop.
Location State to check service and permission state
import 'package:geolocator/geolocator.dart';
sealed class LocationState {
final bool isServiceEnabled;
final LocationPermission permissionState;
const LocationState(
{required this.isServiceEnabled, required this.permissionState});
}
class InitialLocationState extends LocationState {
InitialLocationState({
required super.isServiceEnabled,
required super.permissionState,
});
@override
String toString() =>
'InitialLocationState(isServiceEnabled: $isServiceEnabled, permissionState: $permissionState)';
}
class LoadingLocationState extends LocationState {
@override
String toString() =>
'LoadingLocationState(isServiceEnabled: $isServiceEnabled, permissionState: $permissionState)';
LoadingLocationState({
required super.isServiceEnabled,
required super.permissionState,
});
}
class LoadedLocationState extends LocationState {
final Position position;
LoadedLocationState({
required super.isServiceEnabled,
required super.permissionState,
required this.position,
});
@override
String toString() => 'LoadedLocationState(position: $position)';
}
class LocationErrorState extends LocationState {
final String errorMessage;
LocationErrorState({
required super.isServiceEnabled,
required super.permissionState,
required this.errorMessage,
});
@override
String toString() => 'LocationErrorState(errorMessage: $errorMessage)';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment