해결됨
[2024 최신] [코드팩토리] [초급] Flutter 3.0 앱 개발 - 10개의 프로젝트로 오늘 초보 탈출!
LocationPermission 에러
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
final CameraPosition initialPosition = CameraPosition(
target: LatLng(37.5214, 126.9246),
zoom: 17
);
@override
initState(){
super.initState();
checkPermission();
}
checkPermission( ) async {
final inLocationEnabled = await Geolocator.isLocationServiceEnabled();
if(!inLocationEnabled){
throw Exception('위치 기능을 활성화 해주세요');
}
LocationPermission checkedPermission = await Geolocator.checkPermission();
if(checkedPermission == LocationPermission.denied){
checkedPermission = await Geolocator.requestPermission();
}
if(checkedPermission != LocationPermission.whileInUse || checkedPermission != LocationPermission.always) {
throw Exception('권한을 허가해 주세요');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: GoogleMap(
initialCameraPosition: initialPosition,
)
)
],
),
);
}
}강의를 보면서 공부 도중 테스트를 하는데LocationPermission.whileInUseLocationPermisson.always 의 if문에서 Exception으로 던지는데 해결방법을 모르겠습니다.