Google Maps Flutter plugin method not working as expected - android-studio

I have been using google maps for flutter in Android Studio for about two months and now the GoogleMapsController.animateCamera is throwing this exception:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException
(No implementation found for method camera#animate on channel plugins.flutter.io/google_maps_0)
The only new code that has been introduced between it working and not working is this method:
void searchAndNavigate() {
Geolocator().placemarkFromAddress(searchAddress).then((result) async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target:
LatLng(result[0].position.latitude, result[0].position.longitude), zoom: 15.0)));
});
}
The method that I also want to use and that was working before the introduction of this new method is:
Future<void> setLocation(LocationData location) async {
final GoogleMapController controller = await _controller.future;
LatLng newLocation = LatLng(location.latitude, location.longitude);
CameraPosition cameraPosition = CameraPosition(
zoom: 15.0,
target: newLocation,
);
await controller.animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
await getData(newLocation);
}
Anyone have any idea why this is happening? I have recompiled the application and run flutter doctor/upgrade/clean

Related

#azure/msal-browser TypeError: this.startPerformanceMeasurement is not a function

Introduction
Because there is no build in Auth library for nuxt 3 yet, I am trying to create my own composable called useAuth.
The Problem
I am getting a startPerformanceMeasurement error when i try to call the loginRedirect or loginPopup method.
Uncaught (in promise) TypeError: this.startPerformanceMeasurement is not a function
at PerformanceClient2.startMeasurement (PerformanceClient.ts:100:45)
at BrowserPerformanceClient2.startMeasurement (BrowserPerformanceClient.ts:46:55)
at RedirectClient2.<anonymous> (StandardInteractionClient.ts:204:64)
at step (_tslib.js:87:23)
at Object.next (_tslib.js:68:53)
at _tslib.js:61:71
at new Promise (<anonymous>)
at __awaiter (_tslib.js:57:12)
at StandardInteractionClient2.getDiscoveredAuthority (StandardInteractionClient.ts:202:115)
at RedirectClient2.<anonymous> (StandardInteractionClient.ts:142:48)
Code
composables/useAuth.js
import * as msal from '#azure/msal-browser'
let state = {
authService: null,
}
export const useAuth = () => {
// use public configuration from nuxt
var config = useAppConfig();
//create authentication instance
state.authService = new msal.PublicClientApplication(config.msalConfig);
//return signIn method
return {
signIn
}
}
const signIn = async () => {
const tokenRequest = {
scopes: [
'openid',
'offline_access',
'Users.Read'
],
}
const response = await state.authService
.loginRedirect(tokenRequest)
.then(() => {
})
.catch(err => {
console.log(err) //TypeError: this.startPerformanceMeasurement is not a function
});
}
Index.vue
<script setup>
if(process.client) {
const auth = useAuth()
auth.signIn()
}
</script>
Apparently this is a bug in the MSAL library.
As mentioned in this issue on Github, they're currently working on a fix.
As a temporary solution, you could downgrade to a previous version. Downgrading might be as simple as just removing the caret character (^) when referring to the version in your package.json.
Edit: They've released a fix as part of msal-common v9.1.1.
I tested by downgrading multiple releases and the first one working was #azure/msal-browser#2.31.0
Faced this issue too. It is caused due to a bug from Microsoft. The versions that work fine are:
"#azure/msal-browser": "2.32.0",
"#azure/msal-common": "9.0.1",
"#azure/msal-react": "1.5.0",
Please ensure to remove the ^ in the number to keep it pinned.
Watch https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/5569 for updates from MS.

vscode typescript intellisense for exported modules

IntelliSense works as expected in my main project file where I imported a third-party library to my project;
Example: I'm using a library "Directus," however, when exporting the class and importing in another file in my project, IntelliSense stops working.
import { Directus } from '#directus/sdk';
export class Editor {
public async directus(): Promise<any> {
let directus = new Directus("http://localhost:8055/");
await directus.auth.login({
email: "email#admin",
password: "password",
});
return directus
}
}
When importing the class in another file test.ts (IntelliSense stops working)
I'm not sure if this is a vscode issue or typescript configuration problem.
import { Editor } from ".";
let test = new Editor();
You are trying to access a property on an async method. Instead use this syntax:
const test = new Editor(); // create object instance
const directus = await test.directus(); // call method returning promise and await its value
directus.propertyName // access a property on the value
Thanks to #jsejcksn for pointing out that I needed to await for the method.
I have also needed to return the correct type, instead of using any returning TypeMap
import { Directus, TypeMap } from '#directus/sdk';
export class Editor {
public async directus(): Promise<Directus<TypeMap>> {
let directus = new Directus("http://localhost:8055/");
await directus.auth.login({
email: "email#admin",
password: "password",
});
return directus
}
}
Now IntelliSense works as expected.

Can't get ref on realtime database with emulator

I am trying to attach a listener to realtime database on local emulator with another database selected but it's giving me a weird error.
Here is the code I am using:
const functions = require("firebase-functions");
const handler = async (snapshot, context) => {
console.log(snapshot);
console.log(context);
}
const target = functions.database
.instance("test-db")
.ref("/docs/{docID}")
module.exports = {
create: target.onCreate(handler),
update: target.onUpdate(handler),
delete: target.onDelete(handler),
}
Here is the error that I am getting:
i functions: Beginning execution of "operationsListenerRealtime-update"
! functions: TypeError: Cannot read property 'startsWith' of undefined
at new DataSnapshot (Q:\Projects\test-project\firebase\functions\node_modules\firebase-functions\lib\providers\database.js:270:44)
at RefBuilder.changeConstructor (Q:\Projects\test-project\firebase\functions\node_modules\firebase-functions\lib\providers\database.js:155:28)
at cloudFunction (Q:\Projects\test-project\firebase\functions\node_modules\firebase-functions\lib\cloud-functions.js:133:34)
at C:\Users\duoqu\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:592:16
at runFunction (C:\Users\duoqu\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:579:15)
at runBackground (C:\Users\duoqu\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:591:11)
at processBackground (C:\Users\duoqu\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:574:11)
at invokeTrigger (C:\Users\duoqu\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:649:19)
at handleMessage (C:\Users\duoqu\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:736:15)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
! Your function was killed because it raised an unhandled error.
Clearly I am trying to connect realtime database that is test-db, I also tried writing http://localhost:7002/?ns=test-db but still no luck. I digged deep into the error and saw this thing:
/**
* Interface representing a Firebase Realtime Database data snapshot.
*/
class DataSnapshot {
constructor(data, path, // path will be undefined for the database root
app, instance) {
this.app = app;
if (app && app.options.databaseURL.startsWith('http:')) {
// In this case we're dealing with an emulator
this.instance = app.options.databaseURL;
}
else if (instance) {
// SDK always supplies instance, but user's unit tests may not
this.instance = instance;
}
else if (app) {
this.instance = app.options.databaseURL;
}
else if (process.env.GCLOUD_PROJECT) {
this.instance =
'https://' + process.env.GCLOUD_PROJECT + '.firebaseio.com';
}
this._path = path;
this._data = data;
}
I think the issue may be related to this part of the code
Also the instance function takes parameters like this.
EDIT: I have confirmed that with proper node version it still is giving me the same error.

Phaser 3 ScaleManager exception

I am trying to enable fullscreen in my game written in Phaser 3.
I am doing it from Scene class via
this.game.scale.startFullScreen();
but getting error in f12 browser console
Uncaught TypeError: this.game.scale.startFullScreen is not a function
at TitleScene.<anonymous> (TitleScene.js:23)
at InputPlugin.emit (phaser.js:2025)
at InputPlugin.processDownEvents (phaser.js:167273)
...
In docs ScaleManager class has startFullScreen method.
Why console tells me it doesn't?
This is the full code of TitleScene.js:
export class TitleScene extends Phaser.Scene {
constructor ()
{
const config =
{
key: 'TitleScene'
}
super(config);
}
preload ()
{
this.load.image('Title', 'assets/Title.png');
}
create ()
{
this.background = this.add.image(960, 540, 'Title');
this.input.manager.enabled = true;
this.input.once('pointerdown', function () {
this.scene.start('MainScene');
this.game.scale.startFullScreen(); // here is the error
}, this);
}
}
There are two problems prevented me from resolving this problem:
I followed examples from here
https://www.phaser.io/examples/v2
But I am using the third version Phaser. And everyone who uses the same must follow examples from here
https://www.phaser.io/examples/v3
You must pay attention to url while using their site with examples. Both pages are the same from the first look. But urls are different. Also there are warning after each example using the second (old) version of engine.
And finally this function name is not startFullScreen but startFullscreen :)

Are Decorators allowed in NodeJS?

I'm trying to run the following code in NodeJS using terminal
function addStringToName(target, name, descriptor) {
const fn = descriptor.value;
descriptor.value = wrestler => {
fn.call(target, wrestler + ' is a wrestler');
};
}
class Wrestler {
#addStringToName
setName(name) {
this.name = name;
}
sayName() {
console.log(this.name);
}
}
const w = new Wrestler();
w.setName('Macho Man');
w.sayName();
Getting the following error
Can Decorators be used in NodeJS if yes what is wrong with the written code ?
Unfortunately, no. You have to use TypeScript in order to have decorators enabled. Moreover, even TypeScript doesn't support it natively. You will have to have target: "ES5" at least and "experimentalDecorators": true.
You can find more about decorators and TypeScript here: https://www.typescriptlang.org/docs/handbook/decorators.html

Resources