how do i resolve' as prefix' in flutter error - flutter

The name 'LocationAccuracy' is defined in the libraries 'package:geolocation/geolocation.dart', 'package:geolocator/geolocator.dart' and 'package:location_platform_interface/location_platform_interface.dart (via package:location/location.dart)'.
Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.dartambiguous_import

This message is because there's a LocationAccuracy defined in more than one library. So you need define from which library you are getting this LocationAccuracy. So you need specify a prefix after the import like this:
import 'package:geolocation/geolocation.dart' as geo; // or whatever name you want
import 'package:geolocator/geolocator.dart' as geolocator; // or whatever name you want
And then you can refer to the specific LocationAccuracy you want to use in this way:
geo.LocationAccuracy or
geolocator.LocationAccuracy

Related

Is there a way to "export as" on flutter? - Correct way to create a 'library'

I want to have all the import packages of my project in one file so I import that file everywhere.
I created imports.dart, I export all packages but I don't know how to do it when I need to add a tag, like: import 'package:http/http.dart' as http;
When I write export 'package:http/http.dart' as http; I get an error.
You can import any package like http package. You don't need to export it with another name.
Let's say you made a package with a class named "CidQu" then you want to use this package in your code. You can simply use
import 'package:my_package/package.dart';
variable = CidQu().func;
But if you use "import as", your class needs to start with another name.
import 'package:my_package/package.dart' as defne;
variable = defne.CidQu().func;
That's all matters, you don't need to export with another name. And I believe there is nothing called "export as".

Don't import implementation files from another package when import a public class in flutter

When I import a public class in Flutter like this:
import 'package:wheel/src/log/app_log_handler.dart';
shows the waring:
Don't import implementation files from another package.
this is the waring detail:
why give this tips? what is the best way to handle it? I really want the log handler to public because I want all of my project use the same log handler, I do not want put the log handler to every project every time by the copy paste way.By the way, I import package like this:
wheel:
git:
url: https://github.com/jiangxiaoqiang/wheel.git
ref: main
TLDR
The package should have a file that only shows the selected files such as `'package:wheel/wheel.dart``
You should not import the 'package:wheel/src/log/app_log_handler.dart';directly.
Instead import 'package:wheel/wheel.dart`;
This import will export all required public types needed to work with the library.
Normally this files content will be just exports like this
export 'package:wheel/src/log/app_log_handler.dart';
export 'package:wheel/src/widgets/wheel_btn.dart';
export 'package:wheel/src/widgets/wheel_switch_two.dart';
export 'package:wheel/src/widgets/wheel_switch.dart';
See also the documentation on this.

Google Places API in Flutter

I am working on google places API with Flutter. I am working by referring the example. But I got errors for google places API classes as
Eg:
Undefined class 'GoogleMapsPlaces'.
Try changing the name to the name of an existing class, or creating a class with the name
I imported the flutter_google_places in my dart file as:
import 'package:flutter_google_places/flutter_google_places.dart'; But still I got the error for all classes.
Using flutter_google_places version 0.2.3.
GoogleMapPlaces is available on different library, not in flutter_google_places...
it's available on https://pub.dev/packages/google_maps_webservice
you can find another package for google place google_place
var googlePlace = GooglePlace("Your-Key");
var result = await googlePlace.autocomplete.get("1600 Amphitheatre");
You need to import
import 'package:google_maps_webservice/places.dart'; in your main.dart.

Having problems extending Quill

I'm hitting some problems extending Quill.
I want to modify the List and ListItem classes in Quill, so I tried to copy formats/list.js into my code base as a starting point. I then import my local copy and register it with Quill like so...
import { List, ListItem } from './quill/list';
Quill.register({
'formats/list': List,
'formats/list/item': ListItem
}, true);
However, when I attempt to create a list in the editor the code crashes in the List class with the following error:
ParchmentError {message: "[Parchment] Unable to create list-item blot", name: "ParchmentError"}
This happens on this line... https://github.com/quilljs/quill/blob/develop/formats/list.js#L99
I assume it relates to the imports I was forced to change, but I can't figure out what's wrong. I've not made any other changes to list.js. The original file has the following:-
import Block from '../blots/block';
import Container from '../blots/container';
Which I changed to this:-
import Quill from 'quill';
let Block = Quill.import('blots/block');
let Container = Quill.import('blots/container');
Is the way I am importing wrong? What is causing the error?
Figured it out (well a colleague did).
I needed to import Parchment like so :-
let Parchment = Quill.import('parchment');
instead of import Parchment from 'parchment';
This is because you'll end up with a different static Parchment class to the one used internally to Quill, so asking Quill for it's instance ensures you are both working with the same one (ie, the one where the blots were registered).
I came across that problem a couple hours ago.
In Quill's source code, List is a default export while ListItem is a named export.
So your import should look like this:
import List, { ListItem } from './quill/list';
Be sure to export them appropriately on your custom list.js file.
Good luck!

Go + Revel: How to import custom package?

I am following tutorial of chat room covered here
I changed it to import a local package instead of using the sample from ravel's github. I changed it into something like this in one of the controllers (refresh.go in the tuts):
import (
"./../chatroom"
"github.com/revel/revel"
)
And chatroom was in the right directory:
- app
- chatroom
- chatroom.go
- controllers
- refresh.go
- app.go
package chatroom was also initialized already in chatroom.go.
But when running the code, I received this error:
The Go code app/tmp/main.go does not compile: local import "./../chatroom" in non-local package
What am I doing wrong here?
It would be best, following this answer to not use a relative path, but a path from the $GOPATH/src
In your case, is $GOPAHT/src includes app chatroom, you would use
import app/chatroom
The OP comments:
working, but I have to include my app name, something like myapp/app/chatroom,
That makes sense, if $GOPATH/src contains the folder myapp.