dart 未从firebase远程配置加载颜色

wnavrhmk  于 2023-03-21  发布在  其他
关注(0)|答案(1)|浏览(82)

你好,我正在使用webview,我想动态改变菜单中的标题颜色。但是,这在热加载时不会发生。我做错了什么?

final labelColor = Colors.orange;

  final FirebaseRemoteConfig _remoteConfig = FirebaseRemoteConfig.instance;
  Future<void> _initConfig() async {
    await _remoteConfig.setConfigSettings(RemoteConfigSettings(
      fetchTimeout: const Duration(
          seconds: 1), // a fetch will wait up to 10 seconds before timing out
      minimumFetchInterval: const Duration(
          seconds:
              10), // fetch parameters will be cached for a maximum of 1 hour
    ));

    _fetchConfig();
  }

  // Fetching, caching, and activating remote config
  void _fetchConfig() async {
    await _remoteConfig.fetchAndActivate();
  }

  @override
  void initState() {
    _initConfig();
    super.initState();
  }

这是我的菜单代码,我试图改变颜色

selectedItemColor: _remoteConfig.getString('labelColor').isNotEmpty ? _remoteConfig.getString('labelColor') as Color : labelColor,

Firebase中的密钥-x1c 0d1x

4nkexdtk

4nkexdtk1#

必须在获取数据后重新生成状态。
试试这个。

Future<void> _initConfig() async {
    await _remoteConfig.setConfigSettings(RemoteConfigSettings(
      fetchTimeout: const Duration(
          seconds: 1), // a fetch will wait up to 10 seconds before timing out
      minimumFetchInterval: const Duration(
          seconds:
              10), // fetch parameters will be cached for a maximum of 1 hour
    ));

    await _fetchConfig();
     setState((){}); <--------------------- add this here

  }

使_fetchConfig返回类型Future<void>

Future<void> _fetchConfig() async {
    await _remoteConfig.fetchAndActivate();
  }

相关问题