Created
April 27, 2024 00:16
-
-
Save khkred/f71937072766332eae5241bebfc631f2 to your computer and use it in GitHub Desktop.
Location State to check service and permission state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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