The imported library 'package:geolocator/model/position.dart' can't have a part-of directive - dart

In my flutter app I have been using these following plugin permission_handler, geolocator and google_api_availibility.
I could have added this plugin from flutter package from pubspec.yml, however, in my app i am using google_map_flutter plugin which has been using AndroidX support libraries. Due this reason I have added those library locally with some changes to work with AndroidX. So my app structure and pubspecs looks like this.
So in my app pubspecs.yml
dev_dependencies:
flutter_test:
sdk: flutter
permission_handler:
path: my_permission_handler
geolocator:
path: flutter-geolocator
My my_permission_handler's pubspecs.yml
flutter:
plugin:
androidPackage: com.baseflow.permissionhandler
pluginClass: PermissionHandlerPlugin
My api_availibility's pubspec.yml
flutter:
plugin:
androidPackage: com.baseflow.googleapiavailability
pluginClass: GoogleApiAvailabilityPlugin
My geolocator's pubspec.yml
dependencies:
meta: "^1.0.5"
flutter:
sdk: flutter
permission_handler:
path: ../my_permission_handler
google_api_availability:
path: ../flutter-google-api-availability
Now when in one of the project's classes I tried to import a model class from geolocator like this
but it shows this error The imported library 'package:geolocator/model/position.dart' can't have a part-of directive
I have no idea what I'm doing wrong here, please help me.

First of let's look into the code for package:geolocator/modles/position.dart
It says part of geolocator; at the very beginning of the file meaning this class is a part of the plugin which is exposed in the file package:geolocator/ like this part 'models/position.dart';. So here in your client code you don't need to import the class Position this way.
if you modify your import statement this way the error will be gone
import 'package:geolocator/geolocator.dart';
I hope it helps.

Related

How to add a swagger dependency in pubspec.yaml of flutter

I'm a new developers with flutter, and i want to use "swagger" in my application. I add the dependencies of swagger in pubspec.yaml, but there's always an error.
pubspec.yaml:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
swagger: ^1.0.0
when i clicked Packages get, this is the following output:
Running "flutter packages get" in my_first_app...
Because my_first_app depends on swagger ^1.0.0 which doesn't match any versions, version solving failed.
pub get failed (1)
Process finished with exit code 1
How can i use swagger in my Flutter application?
You probably should use instead
open_api: ^2.0.1
swagger is deprecated and not compatible with Dart 2 and the requested version 1.0.0 doesn't exist at all.
From https://pub.dartlang.org/packages/swagger#-readme-tab-

Flutter: How to resolve Error importing package:http/http.dart

I am very new to Flutter, and stuck at the following error:
package:http/http.dart That library is in a package that is not known.
Maybe you forgot to mention it in your pubspec.yaml file?
Please help in resolving this error.
Go to your pubspec.yaml file , and add the http dependency:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
http: any
Remember, the indentation must be the same as 'flutter' or 'cupertino_icons'
And don't forget to run this command in your terminal :
flutter packages get
I had the same problem. You just have to add latest http dependencies in pubspec.yaml
Here is the full code,
dependencies:
flutter:
sdk: flutter
http: ^0.12.0+1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
Don't forget to change verson no. of http
To check latest version of http click here
If you are running app directly from command line then you could also do:
with Flutter:
$ flutter packages get
with pub:
$ pub get
I've found that, when in VS Code, you might need to restart the editor to get it to see the new http module that 'pub get' pulled in. You can have your .dart code and pubspec.yaml exactly right but you still get the compiler/lint error.
You need to import like this:
import 'package:http/http.dart' as http;
add below to pubspec.ymel file
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
http: ^0.12.0+1
use flutter pub to find the latest version
call
flutter packages get
1.Install http package
flutter pub add http
2.check pubspec.yaml file
dependencies:
http: ^0.13.4
3.Import in file
import 'package:http/http.dart';
Reference
just got to pubspec.yaml file and tweak some changes in file
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
http:
under dependencies section just add http like in code description .
flutter will automatically resolve it and will add updated version of http .
You have to add the http dependency in the pubspec.yaml file as shown below:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
http: ^0.12.0+2
Please take note of the indentation. After doing the above, run the below command in your terminal:
flutter packages get
As at the time of writing this, the latest http version is 0.12.0+2. You can learn more by visiting this link.
this worked for me:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
http: any
then:
flutter doctor -v
Finally:
flutter packages get
1. Add this to your package's pubspec.yaml file:
dependencies:
http: ^0.12.1
2. install it :
$ flutter pub get
3. Now in your Dart code, you can use:
import 'package:http/http.dart' as http;
Add below to pubspec.yaml file
dependencies:
http: ^0.12.0+1
Or Just add http
dependencies:
http:
flutter will automatically used latest version of http .
Then use pub get
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
http: ^0.12.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- images/
try to update the sdk versions and then pub get or flutter pub get to get the packages get install
just add in pubspec.yaml
http: ^0.12.0+2
like as
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
http: ^0.12.0+2
and run in terminal
flutter pub get
finally add in class
import 'package:http/http.dart' as http;
When I got this issue, I just close the project from Android Studio (File -> Close Project). And then open it again.
That works for me.
Simply just Restart the project.
But Make sure to add the certain dependency to the pubspec.yaml file and do pub get.
-Just run this below command in your project directory to install http module
flutter pub add http
You first find 'dependencies:' in pubspec.yaml
then under 'dependencies:' type http: ^0.12.0+2 and then press ctrl + s to run get packages.
sample:
dependencies:
http: ^0.12.0+2
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
cupertino_icons: ^0.1.2
http: any
http:
have to be align with the other dependencies.
I had the same issue although I had the latest http package in Pubspec.yaml file. This error was still in there I did these 2 steps and error was resolved.
Remove import 'dart:_http'; if it is there
Add import 'dart:convert';

flutter Got socket error trying to find package android_alarm_manager: ^0.1.0

I just tried to get package from pubspec.yaml (with flutter packages get command) in my Flutter project but it raised this error :
Got socket error trying to find package android_alarm_manager: ^0.1.0"
I'm working on my company computer (Windows 7) that is behind proxy but I absolutely have no problem for other packages (ex. font_awesome_flutter: 6.0.0).
I tried with flutter beta version.
pubspec.yaml
name: background
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.0
font_awesome_flutter: 6.0.0
android_alarm_manager: ^0.1.0
isolate: ^2.0.0
dev_dependencies:
flutter_test:
sdk: flutter
uses-material-design: true
remove the proxy you are using first then get the package again

package "dart_to_js_script_rewriter" is not a dependency

I just started learning dart.
first I created an angular2-dart based project from https://angular.io/docs/dart/latest/quickstart.html and it worked properly.
now I want to add auth0-lock dart package from https://pub.dartlang.org/packages/auth0_lock, so I modified pubspec.yaml to the following:
name: go_dart_angular2_zingchart
description: Go Dart Angular2 with ZingChart Started Kit
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
dependencies:
angular2: ^2.0.0-beta.18
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
auth0_lock: ^0.1.0
transformers:
- angular2:
platform_directives:
- 'package:angular2/common.dart#COMMON_DIRECTIVES'
platform_pipes:
- 'package:angular2/common.dart#COMMON_PIPES'
entry_points: client/web/main.dart
- dart_to_js_script_rewriter
and now when I execute pub get I get the following error:
Error on line 15, column 3 of ../../../.pub-cache/hosted/pub.dartlang.org/auth0_lock-0.1.0/pubspec.yaml: Error loading transformer "dart_to_js_script_rewriter": package "dart_to_js_script_rewriter" is not a dependency.
- dart_to_js_script_rewriter
^^^^^^^^^^^^^^^^^^^^^^^^^^
since I'm new to dart and not entirely sure what I'm doing.. I have no idea how to fix this :)
any ideas ?
thanks!
I get the same error when adding auth0_lock: ^0.1.0 to my dependencies and running pub get. The error message says that "dart_to_js_script_rewriter" is not a dependency in the pubspec.yaml of the auth0_lock package. It looks like it's added under dev_dependecies if you look here. Dev dependencies of any dependent packages are ignored. Pub only gets your package’s dev dependencies.
So I think this is a problem in their package.
So, what I did was I went to https://github.com/andresaraujo/auth0_lock.dart and cloned the package, added it into my own project root in a directory called auth0_lock. And then, in my pubspec.yaml i put:
auth0_lock:
path: auth0_lock
After that I can import it using
import 'package:auth0_lock/auth0_lock.dart';

Pub build produces warning every build: 'Can't find 'animate' in the library 'angular'.'

I'm boldly stepping into the world of AngularDart, admittedly not knowing too much Dart itself yet. I'm creating a new application that does nothing (yet), except includes the latest 'angular' package.
I'm using Dart 1.2.0 and AngularDart 0.9.9.
Very simple pubspec:
name: myapp
dependencies:
angular: any
My app layout:
pubspec.yaml
pubspec.lock
\lib
\packages
\web
In web I have a simple myapp.dart:
import 'package:angular/angular.dart';
main() {
}
My build seems to work fine, but I get the following warning:
Dart: Build
[Warning from Dart2JS on myapp|web/myapp.dart]:
packages\angular\angular.dart:31:23: Hint: Can't find 'animate' in the library 'angular'.
Is 'animate' spelled right?
#MirrorsUsed(targets: const [
^^^^^^^^
My question is, what does this mean, and is this anything to be concerned about?
This was a bug in AngularDart 0.9.9 and is fixed in current versions.

Resources