简体   繁体   中英

Firebase Remote Config Flutter macOS don't run

I'm trying to use remote config values when I start my app.

The objective of this remote config is get the "url" and "key" of my db

This is my main.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Future.wait([
    Firebase.initializeApp(),
  ]);

  await RemoteConfig().start();

  runApp(ModularApp(
    module: AppModule(),
    child: const AppWidget(),
  ));
}

In my main.dart I call the RemoteConfig().start, this call this function in this class

import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/services.dart';
import 'package:flutter_modular/flutter_modular.dart';

class RemoteConfig {
  late FirebaseRemoteConfig _firebaseRemoteConfig;

  RemoteConfig._internal();
  static final RemoteConfig _singleton = RemoteConfig._internal();
  factory RemoteConfig() => _singleton;

  Future<void> start() async {
    _firebaseRemoteConfig = FirebaseRemoteConfig.instance;

    await _firebaseRemoteConfig.setConfigSettings(
      RemoteConfigSettings(
        fetchTimeout: const Duration(seconds: 30),
        minimumFetchInterval: const Duration(minutes: 1),
        // minimumFetchInterval: const Duration(days: 30),
      ),
    );
    await _firebaseRemoteConfig.fetchAndActivate();
  }

  Future<void> forceFetch() async {
    try {
      _firebaseRemoteConfig = FirebaseRemoteConfig.instance;

      await _firebaseRemoteConfig.setConfigSettings(
        RemoteConfigSettings(
          fetchTimeout: const Duration(seconds: 30),
          minimumFetchInterval: Duration.zero,
        ),
      );
      await _firebaseRemoteConfig.fetchAndActivate();
    } on PlatformException catch (exception) {
      Modular.to.navigate("/error");
      throw exception.toString();
    } catch (error) {
      Modular.to.navigate("/error");
      throw ("Erro ao buscar Configuração Remota");
    }
  }

  getValueOrDefault({
    required String key,
    required dynamic defaultValue,
  }) {
    switch (defaultValue.runtimeType) {
      case String:
        var firebaseValue = _firebaseRemoteConfig.getString(key);
        return firebaseValue != "" ? firebaseValue : defaultValue;
      case int:
        var firebaseValue = _firebaseRemoteConfig.getInt(key);
        return firebaseValue != 0 ? firebaseValue : defaultValue;
      case bool:
        var firebaseValue = _firebaseRemoteConfig.getBool(key);
        return firebaseValue != false ? firebaseValue : defaultValue;
      case double:
        var firebaseValue = _firebaseRemoteConfig.getDouble(key);
        return firebaseValue != 0.0 ? firebaseValue : defaultValue;
    }
  }
}

And, this is the error that I get when I try to run the macOS app (iOS and Android it's okay)

Restarted application in 461ms.
flutter: AppModule started!
flutter: -- SplashModule INITIALIZED
flutter: -- HomeModule INITIALIZED
flutter: -- SplashModule DISPOSED
flutter: -- LoginModule INITIALIZED
flutter: -- HomeModule DISPOSED
flutter: [firebase_remote_config/internal] Failed to get installations token. Error : Error Domain=com.firebase.installations Code=0 "Underlying error: The operation couldn’t be completed. SecItemAdd (-34018)" UserInfo={NSLocalizedFailureReason=Underlying error: The operation couldn’t be completed. SecItemAdd (-34018), NSUnderlyingError=0x150998e50 {Error Domain=com.gul.keychain.ErrorDomain Code=0 "SecItemAdd (-34018)" UserInfo={NSLocalizedFailureReason=SecItemAdd (-34018)}}}.
#0      StandardMethodCodec.decodeEnvelope
#1      MethodChannel._invokeMethod
<asynchronous suspension>
#2      MethodChannelFirebaseRemoteConfig.fetchAndActivate
<asynchronous suspension>
#3      FirebaseRemoteConfig.fetchAndActivate
<asynchronous suspension>
#4      Remoteconfig.forceFetch
<asynchronous suspension>
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Erro ao buscar Configuração Remota
#0      Remoteconfig.forceFetch
<asynchronous suspension>
flutter: -- LoginModule DISPOSED
flutter: -- HomeModule INITIALIZED
flutter: -- LoginModule INITIALIZED
flutter: -- HomeModule DISPOSED
flutter:
flutter: -- HomeModule INITIALIZED
flutter: -- LoginModule DISPOSED
Lost connection to device.
Exited

And this is my pubspec.yaml

environment:
  sdk: ">=2.17.0 <3.0.0"

dependencies:
  cupertino_icons: ^1.0.5
  flutter:
    sdk: flutter

  flutter_modular: ^5.0.3
  mobx: ^2.1.0
  flutter_mobx: ^2.0.6+4
  shared_preferences: ^2.0.15
  url_launcher: ^6.1.5
  lottie: ^1.4.3
  flutter_svg: ^1.1.5
  dio: ^4.0.6
  google_fonts: ^3.0.1
  appwrite: ^8.1.0
  firebase_core: ^1.23.0
  firebase_analytics: ^9.3.6
  firebase_remote_config: ^2.0.18

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.1

  mobx_codegen: ^2.0.7+3
  build_runner: ^2.2.1
  modular_test: ^2.0.0
  flutter_native_splash: ^2.2.10
  icons_launcher: ^2.0.5

That error code SecItemAdd (-34018) is regarding keychain sharing entitlements. If you follow these instructions, I believe the error should go away: https://stackoverflow.com/a/38543243/5681607

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM