Geolocation has no Method isLocationOperational - dart

i have implement the geolocation Plugin like the instruction says, but when i wanted to use Geolocation.isLocationOperational(). The Method isn't defined.
The Quellcode where i use it:
import 'package:geolocation/geolocation.dart';
import 'dart:async';
void checkGPS() async{
final GeolocationResult result = await Geolocation.isLocationOperational();
if(result.isSuccessful) {
print("Success");
} else {
print("Fail");
}}
in the xml file i added the permission i needed.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
someone have a idea what i make wrong?

Related

Next.js - Metatags not prerendered when using redux-persist

I have a problem with facebook crawler, they only show something like the text below in the thumbnail:
I have an example of a one of my pages: (This is just a test and does not contain open graph tags but even if they are there the fb thumbnail is not working)
import Head from "next/head";
const Test = () => {
return (
<div>
<Head>
<title>Hello</title>
</Head>
<p>Hellow</p>
</div>
);
};
export default Test;
The expected thing is to inspect the source and be able to view this:
<head><title>Hello</title><head>
But instead we I am getting this:
<!DOCTYPE html><html><head><style data-next-hide-fouc="true">body{display:none}</style><noscript data-next-hide-fouc="true"><style>body{display:block}</style></noscript><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills.js?ts=1660199366445"></script><script src="/_next/static/chunks/webpack.js?ts=1660199366445" defer=""></script><script src="/_next/static/chunks/main.js?ts=1660199366445" defer=""></script><script src="/_next/static/chunks/pages/_app.js?ts=1660199366445" defer=""></script><script src="/_next/static/chunks/pages/test.js?ts=1660199366445" defer=""></script><script src="/_next/static/development/_buildManifest.js?ts=1660199366445" defer=""></script><script src="/_next/static/development/_ssgManifest.js?ts=1660199366445" defer=""></script><noscript id="__next_css__DO_NOT_USE__"></noscript></head><body><div id="__next"></div><script src="/_next/static/chunks/react-refresh.js?ts=1660199366445"></script><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/test","query":{},"buildId":"development","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html>
I can view the title once I visit domain.com/test but that's because javascript is filling the title after loading but the problem is that Its supposed to render the title in the beginning.
The problem is here:
import "bootstrap/dist/css/bootstrap.css";
import "../styles/globals.css";
import AppLayout from "../components/layout/AppLayout";
// import { wrapper } from "../store";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { persistor, store } from "../store";
import { injectStore } from "../api";
injectStore(store);
function MyApp({ Component, pageProps }) {
// Use layout that is defined in page, otherwise use the app's layout.
const getLayout =
Component.getLayout ||
function getLayout(page) {
return <AppLayout>{page}</AppLayout>; // App Layout
};
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
{getLayout(<Component {...pageProps} />)}
</PersistGate>
</Provider>
);
}
// export default wrapper.withRedux(MyApp);
export default MyApp;
After I change my code to look like below and it pre-renders the
meta tags and facebook's crawler can view the tags but that involves removing my Redux Provider (which is needed), any ideas?
NOTE: The problem is with redux-persist and PersistGate. I noticed it after testing with a new project and redux (without persisting the state). SEO works normally if working with redux alone.
import "bootstrap/dist/css/bootstrap.css";
import "../styles/globals.css";
import AppLayout from "../components/layout/AppLayout";
// import { wrapper } from "../store";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { persistor, store } from "../store";
import { injectStore } from "../api";
injectStore(store);
function MyApp({ Component, pageProps }) {
// Use layout that is defined in page, otherwise use the app's layout.
const getLayout =
Component.getLayout ||
function getLayout(page) {
return <AppLayout>{page}</AppLayout>; // App Layout
};
return <Component {...pageProps} />;
}
// export default wrapper.withRedux(MyApp);
export default MyApp;
Potential solution:
So basically the is causing the problem of not pre-rendering the meta tags so one option is to add your provider to every page and not wrap your meta-tags inside of the provider but if you have a lot of pages that's not an option so maybe just adding it to the ones that need the provider's data. (of course that is not an option if you are not persisting the state because you would lose your state)
The solution specific to my project
I have different layouts, the only place where I require the store's state is in the admin's dashboard.
So I have a layout for that and in my layout I added the provider because SEO is not important for the dashboard because that has to be seen by few people only.
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { persistor, store } from "../../store";
import { injectStore } from "../../api";
import DashboardLoginCheck from "./DashboardLoginCheck";
injectStore(store);
const DashboardLayout = ({ children }) => {
return (
<>
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<DashboardLoginCheck />
<div className="dashboard">
{children}
</div>
</PersistGate>
</Provider>
</>
);
};
export default DashboardLayout;
And my code in _app.js is:
import "bootstrap/dist/css/bootstrap.css";
import "../styles/globals.css";
import AppLayout from "../components/layout/AppLayout";
function MyApp({ Component, pageProps }) {
const getLayout =
Component.getLayout ||
function getLayout(page) {
return <AppLayout>{page}</AppLayout>; // App Layout
};
return getLayout(<Component {...pageProps} />);
}
export default MyApp;
I know there could be a better solution but this could still help anyone, I hope someone else can help us all with a better solution.

Using BullMQ with NestJs, is it possible to use a config variable as part of a Job name?

I'm trying to use an environment variable value in the nestjs/bull module's #Process() decorator, as follows. How should I provide the 'STAGE' variable as part of the job name?
import { Process, Processor } from '#nestjs/bull';
import { Inject } from '#nestjs/common';
import { ConfigService } from '#nestjs/config';
import { Job } from 'bull';
#Processor('main')
export class MqListener {
constructor(
#Inject(ConfigService) private configService: ConfigService<SuperRootConfig>,
) { }
// The reference to configService is not actually allowed here:
#Process(`testjobs:${this.configService.get('STAGE')}`)
handleTestMessage(job: Job) {
console.log("Message received: ", job.data)
}
}
EDITED with answers (below) from Micael and Jay:
Micael Levi answered the initial question: You can't use the NestJS ConfigModule to get your config into a memory variable. However, running dotenv.config() in your bootstrap function will not work either; you get undefined values for the memory variables if you try to access them from within a Method Decorator. To resolve this, Jay McDoniel points out that you have to import the file before you import AppModule. So this works:
// main.ts
import { NestFactory } from '#nestjs/core';
require('dotenv').config()
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(process.env.PORT || 4500);
}
bootstrap();
You cannot use this on that context due to how decorator evaluation works. At that time, there's no instance created for MqListener class, thus, using this.configService doens't make sense.
You'll need to access process.env. directly. And so will call dotenv (or what lib that read & parses your dot env file) in that file.

angular dart js interop with async / promise awaited in client

clientside.js
async function callClientAsyncFuncWithResult () {
let result = await someService.request();
return result;
}
page.dart
import 'dart:js' as js;
var result = js.context.callMethod('callClientAsyncFuncWithResult');
//I want to do something like var result = await js.context.callMethod('callClientAsyncFuncWithResult');
How in AngularDart do you wait for a client side javascript Promise to return with result before continuing execution in dart? Right now it just flows over the call and I've tried setting the result of callMethod to Future or Promise and it never waits.
I don't think my implementation is correct. How can I achieve this?
You can easily convert a Javascript Promise to a Dart Future, by using the convertNativePromiseToDartFuture API, which is available in dart:html_common.
A simple implementation might look like :
Javascript :
function myCoolFunc () {
return new Promise((resolve, reject) => {
resolve(myLongAwaitedData);
});
}
Dart Interop file :
#JS()
library coolLib;
import 'package:js/js.dart';
import 'dart:async';
#JS()
external Future<T> myCoolFunc ();
Dart file :
import 'dart:html_common';
import 'cool_lib.dart';
main() async {
var myVar = await convertNativePromiseToDartFuture(myCoolFunc());
print(myVar);
}
I found this deeply buried in the Gitter of the Dart Sdk. I hope it can help future Angular Dart users.
Update : This API has changed in Dart 2.6 convertNativePromiseToDartFuture has been replaced with promiseToFuture

React Native: Yet another "Undefined is not an object (evaluating action.type)

I'm developing a CRNA application, however, the store connection is not working and I'm receiving the above error when creating the store.
"Undefined is not an object (evaluating action.type)
Searching for similar problems, I got to this question, which is a reducer being called while passed to the createStore function, which is not my case.
And this one, which is related to AnalyticsTracker called before an async dispatcher, also not my case.
Here's the minimum code to reproduce.
App.js
import React from 'react';
import {
View,
Text
} from 'react-native';
import { Provider } from 'react-redux';
import store from './store';
class App extends React.Component {
render() {
return (
<Provider store={store}>
<View>
<Text>Hello</Text>
</View>
</Provider>
);
}
}
store.js
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import reducer from './reducer';
// Here the error happens
export default createStore(reducer, applyMiddleware(thunk));
reducer.js
import actionTypes from './action_types';
const initialState = {
}
export default (action, state=initialState) => {
// This is the top line on stacktrace
switch (action.type) {
case actionTypes.MY_ACTION:
return state;
}
return state;
}
I have tried a few changes in my code, i.e: removing the middlewares.
Any idea why is it happening? Am I missing something?
I have noticed that your createStore call is false, since enhancers are passed as the third parameter. Change it to:
const store = createStore(persistedReducer, undefined, applyMiddleware(thunk));
Additionally the structure of your reducer is false. Your first parameter in your reducer should be the initialState followed by the action as the second parameter - this is why you get undefined is not an object!.
As described in Reducers, it has to have a signature of (previousState, action) => newState, is known as a reducer function, and must be pure and predictable.
From: https://redux.js.org/recipes/structuringreducers

Implementing java code for youtube-android api

I am building an android app that uses youtube API. I have figured the flow with youtube API but i don't know how start building it in java.I am completely new to using API's.Can anyone please provide a direction?
Please follow this approach. First you should try to download the Youtube player library for Android from the link below:
Youtube Android Player
You should first install it like this: Project -> menu: File > Structure > Dependencies Tab > Add -> library dependency
if it doesn't work, please try one of these two:
Add dependency of the library inside dependency inside build.gradle file of the library u r using, and paste ur library in External Libraries.
OR
Just Go to your libs folder inside app folder and paste all your .jar e.g Library files there Now the trick here is that now go inside settings.gradle file now add this line include ':app:libs' after include ':app' It will definitely work.
Then, you should have a layout like this:
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
And you can have a player activity like this:
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.youtube.YouTube;
import java.io.IOException;
public class YoutubeActivity extends YouTubeBaseActivity{
private YouTubePlayerView playerView;
private YouTube youtube;
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_youtube);
youtube = new YouTube.Builder(new NetHttpTransport(),
new JacksonFactory(), new HttpRequestInitializer() {
#Override
public void initialize(HttpRequest hr) throws IOException {}
}).setApplicationName(this.getString(R.string.app_name)).build();
playerView = (YouTubePlayerView)findViewById(R.id.player_view);
playerView.initialize("Your API Key", new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
if(!b){
String videoId = getIntent().getExtras().getString("videoID");
youTubePlayer.cueVideo(videoId);
}
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Toast.makeText(getApplicationContext(), getString(R.string.failed), Toast.LENGTH_LONG).show();
}
});
}
}

Resources