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.
Related
I have a project which uses flutter_libserialport library on macOS.
I am modifying it to work on web however this library does not work on web.
I am building a web implementation using navigator.serial in javascript which works fine.
However when I attempt to build the project for web I get the following error
/opt/homebrew/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/libserialport-0.2.0+3/lib/src/config.dart:25:8: Error: Not found: 'dart:ffi'
import 'dart:ffi' as ffi;
This makes sense since FFI is not available on web.
But I don't even need the libserialport library on web any way.
How can I get flutter to ignore it?
I tried this however it doesn't contain information on how to exclude a package.
It also does not contain information on how to ignore it specifically for web. It seems to just ignore it in general.
Maybe you should guard your usages of libserialport with the kIsWeb predicate like following:
if(!kIsWeb){
// libserialport code execution here
}
I searched a lot as well and didn't find a way you can do that, I think this should be handled by the package itself not the package's users like in path_provider for instance.
As a workaround I have created a dummy libserialport's SerialPort class for web only as follows:
dummy_serialport.dart:
class SerialPort {
final String name;
static List<String> availablePorts = ['dummy'];
static SerialPortError? lastError;
SerialPort(this.name);
bool openReadWrite() {
return false;
}
}
class SerialPortError {}
// add more properties and functions as needed
main.dart:
import 'package:libserialport/libserialport.dart'
if (dart.library.html) './dummy_serialport.dart'
if (dart.library.io) 'package:libserialport/libserialport.dart';
....
if (!kIsWeb) {
final name = SerialPort.availablePorts.first;
final port = SerialPort(name);
if (!port.openReadWrite()) {
print(SerialPort.lastError);
exit(-1);
}
}
....
....
It's bad, I know :( but it works! maybe you can contact the package author to get more insight and if opening a PR where the interfaces are separated from the FFI implementation so that importing the classes wouldn't break web or something.
I'm getting json data from a wordpress website. Some of the content I fetch can have html codes like ’ or … and I want to convert this to normal caracter like ' or ...
I can't seem to understand what function to use from the dart API to do this.
I've been able to convert them 1 by 1 using RegExp but I'm sure there is a better way to do this.
new RegExp(r'…'),'...'))),
Thanks for the help.
There's a library called html_unescape that can do that, you can find it here.
The steps to get it working are described there but as a quick reference:
1.- Include the dependency on your pubspec.yaml
dependencies:
html_unescape: ^1.0.1+3
flutter:
sdk: flutter
2.- Install the dependeny
Click on Packagets get while on the pubsec.yaml file
3.- Import it and use it:
import 'package:html_unescape/html_unescape.dart';
void main() {
var unescape = HtmlUnescape();
// prints ’ and …
print(unescape.convert('’ and …'));
}
//EDIT
Just as extra info, this is the google query I used to find this:
"convert html entities string flutter"
I have a class TripController that contains a private field _updatedAccount. I created a getter in order to get from outside.
class TripController {
final String _accountId;
final BuildContext _context;
Account _updatedAccount;
Account updatedAccount() => _updatedAccount;
TripController(this._accountId, this._context);
...
}
In another class, where I perfectly have access to the TripController class, I have the code :
onTap: () {
TripController _tripController =
new TripController(_account.id, context);
_tripController.add(context);
_account.trips = _tripController.updatedAccount.trips;
_account.notifyListeners();
},
And here, updatedAccount from _tripController.updatedAccount.trips is underlined in red with the message : The getter 'updatedAccount' isn't defined for the class 'TripController'
Did I misdeclared the getter ?
Okay, I finally fixed it. I don't know why, but I had to delete the code related to TripController, and ther re-write it again. I don't know why, maybe it was an Editor problem, I'm using VScode.
You have declared updatAccount() as a method, not as a getter. Use _tripController.updatedAccount().trips; or change the method to a getter Account get updatedAccount => _updatedAccount;
I faced this error and the problem was my IDE, not my code.
This solution worked for me in Android Studio :
File -> Invalidate Catches... -> Invalidate And Restart
You are using the classic method syntax declaration, in Dart language, prefer using this kind of syntax for getters:
Account get updatedAccount => _updatedAccount;
And call it the way you did.
Else you should call it like a classic method:
_tripController.updatedAccount().trips
Please follow this link for further information:
https://dart.dev/guides/language/language-tour#getters-and-setters
If you want to use import 'package:flutter_svg/svg.dart'; package then you need to follow these steps.
step 1. -> Open the termial in the IDE and run this command -> flutter pub add flutter_svg
step 2. -> Then run this command -> flutter pub get
step 3. -> Now import this package -> import 'package:flutter_svg/flutter_svg.dart';
Try to check the model class name you use might the same with existing name of Widget or Plugin
Check your imported libraries on the top of your file where the problem is. In my case, Android Studio auto-imported an object from the core Flutter library with the same name as the model I've defined on my own.
I just deleted the import and then imported my own object from my_models.dart file.
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!
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.