I have to integrate firebase remote config to my flutter app. From the searches in various sites, I couldn't find the complete solution.
class RemoteConfigurartion{
Future<RemoteConfig> setupRemoteConfig() async {
String value =null;
final RemoteConfig remoteConfig = await RemoteConfig.instance;
remoteConfig.setConfigSettings(RemoteConfigSettings(debugMode: false));
remoteConfig.setDefaults(<String, dynamic>{
'riddle': "off",
});
try {
// Using default duration to force fetching from remote server.
await remoteConfig.fetch(expiration: const Duration(seconds: 0));
await remoteConfig.activateFetched();
} on FetchThrottledException catch (exception) {
// Fetch throttled.
print(exception);
} catch (exception) {
print(
'Unable to fetch remote config. Cached or default values will be '
'used');
}
return remoteConfig;
}
}
This is what I found already. This the result I'm getting:
No implementation found for method RemoteConfig#instance on channel plugins.flutter.io/firebase_remote_config
But I have added all the plugins in the pubspec.yaml and in android gradle folder
Can anyone help me to find out a complete solution to integrate remote config to a flutter app?
Make sure that firebase_core is initialized, and for Android, google-services.json should be in the app folder. Aside from that, there doesn't seem to be any issues on your code. You might've missed some steps during set up.
If you've just added the plugins, it's best to run the app using restart instead of hot reload to ensure that all recently added plugins is included in the build.
Related
I am getting issues while building new ISR/SSR pages with getStaticProps and getStaticPaths
Brief explanation:
While creating ISR/SSR pages and adding new API route never existed before, building on Vercel fails because of building pages before building API routes (/pages/api folder)
Detailed explanation:
A. Creating next SSR page with code (/pages/item/[pid].tsx)
export async function getStaticProps(context) {
const pid = context.params.pid;
//newly created API route
const res = await fetch(process.env.APIpath + '/api/getItem?pid=' + (pid));
const data = await res.json();
return {
props: {item: data}
}
}
export async function getStaticPaths(context) {
//newly created API route
let res = await fetch(process.env.APIpath + '/api/getItemsList')
const items = await res.json()
let paths = []
//multi-language support for the pages
for (const item of items){
for (const locale of context.locales){
paths.push({params: {pid: item.url }, locale: locale})
}
}
return { paths, fallback: false }
}
B. Local checks work, deploying to Vercel
C. During deploying Vercel triggers an error because trying to get data from the API route doesn't exist yet. (Vercel is deploying /pages/item/[pid].tsx first and /api/getItemsList file after). Vercel trying to get data from https://yourwebsite.com/api/getItemsList which does not exist.
Only way I am avoiding this error:
Creating API routes needed
Deploying project to Vercel
Creating [pid].tsx page/s and then deploy it
Deploying final version of code
The big issue with my approach is you are making 1 deployment you don't actually. The problems appears also while remaking the code for your API routes also.
Question: there is an way/possiblity to force Versel to deploy firstly routes and than pages?
Any help appreciated
I am using expo-facebook to integrate a Facebook login using expo and firebase. Everything looks to be working and I log into Facebook but get an OAuthException once I authenticate using Facebook as follows:
Unsuccessful debug_token response from Facebook: {"error":{"message":"(#100) The App_id in the input_token did not match the Viewing App","type":"OAuthException","code":100
I have gone through a lot of issues on Stack Overflow, GitHub and looked at expo documentation as well but to no avail.
I have configured the app id and secrets from Facebook into firebase as required as well as set up the OAuth redirect URI to my Facebook app configuration. The code I have put together to setup the login is as follows:
const signInWithFacebook = async () => {
try {
// const { type, token } = await Facebook.logInWithReadPermissionsAsync(
// facebookAppId,
// {
// permissions: ["public_profile"],
// }
// );
const appId = Constants.manifest.extra.facebook.appId;
const permissions = ["public_profile"]; // Permissions required, consult Facebook docs
await Facebook.initializeAsync({
appId: appId,
});
const { type, token } = await Facebook.logInWithReadPermissionsAsync({
permissions: permissions,
});
console.log(type);
console.log(token);
if (type === "success") {
await firebase
.auth()
.setPersistence(firebase.auth.Auth.Persistence.LOCAL);
const credential = firebase.auth.FacebookAuthProvider.credential(token);
const facebookProfileData = await firebase
.auth()
.signInWithCredential(credential);
//this.onLoginSuccess.bind(this);
console.log(facebookProfileData);
}
} catch ({ message }) {
console.log(message);
alert(`Facebook Login Error: ${message}`);
}
};
I have also setup the relevant configurations in the app.json as follows:
"expo":{
"facebookScheme": "fb123243435566",
"facebookAppId": "123243435566",
"facebookDisplayName": "myapp"
}
The only aspect I am not sure about is where to grab the facebookScheme. Currenltly I have assumed it's fb+AppID. the documenatation mentioned here https://docs.expo.dev/versions/latest/sdk/facebook/
isn't clear. It states:
Configure app.json.
Add the field facebookScheme with your Facebook login redirect URL scheme found here under "4. Configure Your info.plist." It should look like "fb123456". If you do not do this, Facebook will not be able to redirect to your app after logging in.
But I am not sure how to grab that facebookScheme id. I suspect this is where the issue is as expo states that.
Expo Go from the Android Play Store will use the Facebook App ID that you provide, however, all Facebook API calls in the Expo Go from the iOS App Store will use Expo's own Facebook App ID. This is due to underlying configuration limitations.
so I am assuming the facebookScheme is some kind of workaround.
Although I am not sure if it's a working around for the ios standalone app or the expo managed.
Try this:
const { type, token } = await Expo.Facebook.logInWithReadPermissionsAsync(appId, {
permissions: [‘public_profile’, ‘email’],
behavior: Platform.OS === ‘android’ ? ‘web’ : ‘system’,
});
it should specify for the app to open a web browser on login
here's the ref:
https://forums.expo.dev/t/how-to-fix-standalone-android-expo-facebook-login/23922
I am simply trying to upload an image using Firebase CloudFirestore/Storage. This is my method for it:
Future<void> uploadFile() async {
File file = File(croppedImagePath);
try {
int randomNumber = Random().nextInt(10000);
String imageLocation = 'images/image$randomNumber.jpg';
await FirebaseStorage.instance.ref(imageLocation).putFile(file); // <- crash
_addPathToDatabse(imageLocation);
} on FirebaseException catch (e) {
// e.g, e.code == 'canceled'
print(e.message);
}
}
but this crashes with:
Exception has occurred.
MissingPluginException (MissingPluginException(No implementation found for method Task#startPutFile on channel plugins.flutter.io/firebase_storage))
This is what I added in pubspec.yaml :
firebase_core: ^1.3.0
cloud_firestore: ^2.3.0
firebase_storage: ^9.0.0
I tried running flutter clean and also restarted the project several times... What am I missing here? Why is it not working?
I recommend that you check if the file is correct, you can also try converting your file to bytes.
after running Flutter clean, restarting my pc and deleting my derived data it is working again...
I'm trying to create a login with Facebook with Firebase.
My login function is:
public void FacebookLogin()
{
var perms = new List<string>() { "public_profile", "email" };
FB.LogInWithReadPermissions(perms, AuthCallback);
if (FB.IsLoggedIn)
{
string aToken = Facebook.Unity.AccessToken.CurrentAccessToken.UserId;
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
Firebase.Auth.Credential credential = Firebase.Auth.FacebookAuthProvider.GetCredential(aToken);
auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
if (task.IsCanceled)
{
Debug.LogError("SignInWithCredentialAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
}
}
My problem is the warning "Database URL not set in the Firebase config.", followed by a SignInWithCredentialAsync error (System.AggregateException).
How can I change the URL in Firebase config? Where is this Firebase config located?
I'm a newbie in coding, thanks for the support.
I should manage to link all the Id app, Oauth etc correctly( i hope so), I believe the problem is caused by the empty URL for firebase db.
firebaser here
There is a bug in the Firebase games SDKs at the moment, which makes it require that a databaseURL value is specified in the google-services.json and/or google-services-info.plist files. Unfortunately that key is not present anymore, unless you actually use the Realtime Database.
The easiest might be to:
Create a Realtime Database instance in the Firebase console.
Download the updated configuration files and add them to your project again.
Update: I just spotted that the issue on Github also mentions a workaround for the problem.
I have setup firebase config for flutter
According to documentation https://pub.dev/packages/firebase_remote_config#-readme-tab-
My key is
then I have Published also then i tried following code and it will return
'Unable to fetch remote config. Cached or default values will be ''used'
could you please point issue
I have tried those also
Firebase Remote Config - Initial fetch return local default values
Remote config in Flutter app throws exception on fetch
try {
remoteConfig.getString('welcome')[![enter image description here][1]][1]
// Using default duration to force fetching from remote server.
await remoteConfig.fetch(expiration: const Duration(seconds: 0));
await remoteConfig.activateFetched();
} on FetchThrottledException catch (exception) {
// Fetch throttled.
print(exception);
} catch (exception) {
print(
'Unable to fetch remote config. Cached or default values will be '
'used');
}
This worked fine for me,
await remoteConfig.ensureInitialized();
it's work for me
FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.instance;
initializeRemote() async {
// remoteConfig = await setupRemoteConfig();
//!- must be active firebase remote config
bool updated = await remoteConfig.fetchAndActivate();
if (updated) {
print("found");
// the config has been updated, new parameter values are available.
} else {
print("not print");
// the config values were previously updated.
}
await remoteConfig.ensureInitialized().then((value) async {
print("remote value -> ${await remoteConfig.getString("app_version")}");
});
}
Usually when you fight these problems, in the end, everything gets mixed up. I think after the post you could already see the configured value, but the error occurs when querying another parameter name. Add the following line to see the actual error you are getting.
print('EXCEPTION: $exception');
try {
await remoteConfig.fetch(expiration: const Duration(seconds: 0));
await remoteConfig.activateFetched();
String forceUpdateCurrentVersion =
remoteConfig.getString('force_update_current_version');
double newVersion =
double.parse(forceUpdateCurrentVersion.trim().replaceAll(".", ""));
if (newVersion > currentVersion) {
_showVersionDialog(context);
}
} on FetchThrottledException catch (exception) {
// Fetch throttled.
print(exception);
} catch (exception) {
print('EXCEPTION: $exception');
print('Unable to fetch remote config. Cached or default values will be '
'used');
}
Just put value don't put braces for Default value
For Example
Then use below code in flutter
remoteConfig.getString('IT_');
If you are using Android emulator, ensure it has Google play services enabled.