작성
·
58
·
수정됨
0
코드팩토리 디스코드에 질문하면 더욱 빠르게 질문을 받아 볼 수 있습니다!
[코드팩토리 디스코드]
https://bit.ly/3HzRzUM
geolocator 가 import 가 안되는데 어떡하죠?
오류는 아래와 같이 나오구요.
Target of URI doesn't exist: 'package:geolocator/geolocator.dart'.
소스는 아래와 같습니다.
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:geolocator/geolocator.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: 15,
);
checkPermission() async{
final isLocationEnabled = await Geolocator.isLocationServiceEnabled();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [Expanded(child: GoogleMap(initialCameraPosition: initialPosition))],
),
);
}
}
pubspec.yaml 은 아래와 같이 되어 있습니다.
name: chool_check
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1
environment:
sdk: ^3.7.2
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.8
google_maps_flutter: ^2.6.0
geolocator: ^14.0.0
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^5.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/to/asset-from-package
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/to/font-from-package
답변 2
0
0
안녕하세요, 인프런 AI 인턴입니다. moonseok.shin님.
geolocator
패키지가 import
되지 않는 문제는 대부분 pubspec.yaml
파일과 관련된 설정 오류에서 발생합니다. 다음 사항들을 확인해보시기 바랍니다:
패키지 설치 여부 확인: geolocator
패키지가 pubspec.yaml
에 추가되어 있음을 확인하셨으니, flutter pub get
명령어를 실행하여 의존성을 업데이트하십시오. 이를 통해 패키지가 올바르게 설치되었는지를 확인할 수 있습니다.
패키지 버전 호환성 확인: geolocator
패키지의 최신 버전을 사용하는 것이 중요합니다. 때때로 패키지 버전 간의 충돌로 인해 문제가 발생할 수 있습니다. pubspec.yaml
에 명시되어 있는 geolocator
패키지의 버전 번호가 최신인지 확인하고, 필요하다면 최신 버전으로 업데이트하십시오.
패키지 명세 확인: pubspec.yaml
파일 내 dependencies 섹션에 geolocator: ^14.0.0
이 올바르게 기재되어 있는 것을 확인하였습니다. 이 부분이 정확하다면 특별한 문제는 없어 보입니다.
IDE 재시작: 가끔 플러그인이나 캐시 문제가 발생할 수 있습니다. 사용하는 IDE(예: Android Studio, Visual Studio Code)를 재시작하고 다시 시도해보시기 바랍니다.
Flutter SDK와의 호환성 확인: 사용하고 있는 Flutter SDK의 버전이 geolocator
와 호환되는지도 확인해보세요. 프로젝트에 사용하는 Flutter 버전을 flutter --version
명령어로 확인할 수 있습니다.
해당 문제의 해결에 참고할 수 있는 유사 질문이 있습니다:
- Invalid depfile 에러 관련 해결 방안
위 방법들이 문제 해결에 도움이 되지 않는다면, 오류 메시지나 콘솔 로그를 보다 자세히 분석하여 다시 한 번 확인해주세요.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.